<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chapter 19 Using MySQL as a Document Store</title>
<link rel="stylesheet" href="mvl.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets + chunker.py v1.9.2" />
<link rel="start" href="index.html" title="{book-title}" />
<link rel="up" href="" title="" />
<link rel="prev" href="mysql-shell-userguide.html" title="Chapter 18 MySQL Shell" />
<link rel="next" href="mysql-innodb-cluster-userguide.html" title="Chapter 20 InnoDB Cluster" />
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Chapter 19 Using MySQL as a Document Store</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="mysql-shell-userguide.html">Prev</a> </td>
<th width="60%" align="center"></th>
<td width="20%" align="right"> <a accesskey="n" href="mysql-innodb-cluster-userguide.html">Next</a></td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title"><a name="document-store"></a>Chapter 19 Using MySQL as a Document Store</h1>

</div>

</div>

</div>
<div class="toc">
<p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="document-store.html#document-store-legalnotice">19.1 Preproduction Status — Legal Notice</a></span></dt><dt><span class="section"><a href="document-store.html#document-store-concepts">19.2 Key Concepts</a></span></dt><dt><span class="section"><a href="document-store.html#document-store-setting-up">19.3 Setting Up MySQL as a Document Store</a></span></dt><dd><dl><dt><span class="section"><a href="document-store.html#document-store-shell-install">19.3.1 Installing MySQL Shell</a></span></dt><dt><span class="section"><a href="document-store.html#installing-mysql-shell-starting">19.3.2 Starting MySQL Shell</a></span></dt></dl></dd><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python">19.4 Quick-Start Guide: MySQL Shell for Python</a></span></dt><dd><dl><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-introduction">19.4.1 Introduction</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-download">19.4.2 Import Database Sample</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-shell">19.4.3 MySQL Shell</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-collections">19.4.4 Documents and Collections</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-relational-tables">19.4.5 Relational Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-in-tables">19.4.6 Documents in Tables</a></span></dt></dl></dd><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript">19.5 Quick-Start Guide: MySQL Shell for JavaScript</a></span></dt><dd><dl><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-introduction">19.5.1 Introduction</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-download">19.5.2 Import Database Sample</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-shell">19.5.3 MySQL Shell</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-collections">19.5.4 Documents and Collections</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-relational-tables">19.5.5 Relational Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-in-tables">19.5.6 Documents in Tables</a></span></dt></dl></dd><dt><span class="section"><a href="document-store.html#mysql-shell-visual-studio">19.6 Quick-Start Guide: MySQL for Visual Studio</a></span></dt><dt><span class="section"><a href="document-store.html#x-plugin">19.7 X Plugin</a></span></dt><dd><dl><dt><span class="section"><a href="document-store.html#x-plugin-ssl-connections">19.7.1 Using Secure Connections with X Plugin</a></span></dt><dt><span class="section"><a href="document-store.html#x-plugin-options-variables">19.7.2 X Plugin Options and Variables</a></span></dt><dt><span class="section"><a href="document-store.html#x-plugin-system-monitoring">19.7.3 Monitoring X Plugin</a></span></dt></dl></dd></dl>
</div>
<a class="indexterm" name="idm139684678967168"></a><a class="indexterm" name="idm139684678966128"></a><a class="indexterm" name="idm139684678964640"></a><p>
    This chapter introduces an alternative way of working with MySQL as
    a document store, sometimes referred to as <span class="quote">“<span class="quote">using
    NoSQL</span>”</span>. If your intention is to use MySQL in a traditional
    (SQL) way, this chapter is probably not relevant to you.
  </p><p>
    Using MySQL as a document store is currently a preproduction feature
    to which this notice applies:
    <a class="xref" href="document-store.html#document-store-legalnotice" title="19.1 Preproduction Status — Legal Notice">Section 19.1, “Preproduction Status — Legal Notice”</a>.
  </p><p>
    Relational databases such as MySQL usually required a document
    schema to be defined before documents can be stored. The features
    described in this section enable you to use MySQL as a document
    store, which is a schema-less, and therefore schema-flexible,
    storage system for documents. When using MySQL as a document store,
    to create documents describing products you do not need to know and
    define all possible attributes of any products before storing them
    and operating with them. This differs from working with a relational
    database and storing products in a table, when all columns of the
    table must be known and defined before adding any products to the
    database. The features described in this chapter enable you to
    choose how you configure MySQL, using only the document store model,
    or combining the flexibility of the document store model with the
    power of the relational model.
  </p><p>
    These sections cover the usage of MySQL as a document store:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        The <a class="xref" href="document-store.html#document-store-concepts" title="19.2 Key Concepts">Section 19.2, “Key Concepts”</a> section covers
        concepts like Document, Collection, Session, and Schema to help
        you understand how to use MySQL as a document store.
      </p></li><li class="listitem"><p>
        The <a class="xref" href="document-store.html#document-store-setting-up" title="19.3 Setting Up MySQL as a Document Store">Section 19.3, “Setting Up MySQL as a Document Store”</a> section explains
        how to configure X Plugin on a MySQL Server, so it can
        function as a document store, and how to install MySQL Shell
        to use as a client.
      </p></li><li class="listitem"><p>
        The MySQL Shell is an interactive interface to MySQL
        supporting JavaScript, Python, or SQL modes. You can use the
        MySQL Shell to prototype applications, execute queries and
        update data. The <span class="emphasis"><em>quick-start guides
        (tutorials)</em></span> help you to get started using
        MySQL Shell.
      </p><p>
        The quick-start guide for JavaScript is here:
        <a class="xref" href="document-store.html#mysql-shell-tutorial-javascript" title="19.5 Quick-Start Guide: MySQL Shell for JavaScript">Section 19.5, “Quick-Start Guide: MySQL Shell for JavaScript”</a>.
      </p><p>
        The quick-start guide for Python is here:
        <a class="xref" href="document-store.html#mysql-shell-tutorial-python" title="19.4 Quick-Start Guide: MySQL Shell for Python">Section 19.4, “Quick-Start Guide: MySQL Shell for Python”</a>.
      </p></li><li class="listitem"><p>
        <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/" target="_top">MySQL Shell 8.0 (part of MySQL 8.0)</a> provides more detailed information
        about using MySQL Shell.
      </p></li><li class="listitem"><p>
        <span class="emphasis"><em>X DevAPI User guide.</em></span>
      </p><p>
        Clients that communicate with a MySQL Server using the
        X Protocol can use the X DevAPI to develop
        applications. For example MySQL Shell and MySQL Connectors
        provide this ability by implementing the X DevAPI.
        X DevAPI offers a modern programming interface with a
        simple yet powerful design which provides support for
        established industry standard concepts. See
        <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/" target="_top">X DevAPI User Guide</a> for in-depth tutorials on
        using X DevAPI.
      </p></li><li class="listitem"><p>
        The following MySQL products support the X Protocol and
        enable you to use X DevAPI in your chosen language to
        develop applications that communicate with a MySQL Server
        functioning as a document store.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
            MySQL Shell provides implementations of X DevAPI in
            JavaScript and Python.
          </p></li><li class="listitem"><p>
            Connector/C++
          </p></li><li class="listitem"><p>
            Connector/J
          </p></li><li class="listitem"><p>
            Connector/Node.js
          </p></li><li class="listitem"><p>
            Connector/NET
          </p></li><li class="listitem"><p>
            Connector/Python
</p></li></ul>
</div>
</li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="document-store-legalnotice"></a>19.1 Preproduction Status — Legal Notice</h2>

</div>

</div>

</div>
<p>
      This documentation is in preproduction status and is intended for
      demonstration and preliminary use only. It may not be specific to
      the hardware on which you are using the software. Oracle
      Corporation and its affiliates are not responsible for and
      expressly disclaim all warranties of any kind with respect to this
      documentation and will not be responsible for any loss, costs, or
      damages incurred due to the use of this documentation.
</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="document-store-concepts"></a>19.2 Key Concepts</h2>

</div>

</div>

</div>
<p>
      This section explains the concepts introduced as part of using
      MySQL as a document store.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h3 class="title"><a name="document-store-concept-document"></a>Document</h3>
</div>
</div>
</div>
<p>
        A Document is a set of key and value pairs, as represented by a
        JSON object. A Document is represented internally using the
        MySQL binary JSON object, through the JSON MySQL datatype. The
        values of fields can contain other documents, arrays, and lists
        of documents.
      </p><pre data-lang="json" class="programlisting">
{
    "GNP": .6,
    "IndepYear": 1967,
    "Name": "Sealand",
    "_id": "SEA",
    "demographics": {
        "LifeExpectancy": 79,
        "Population": 27
    },
    "geography": {
        "Continent": "Europe",
        "Region": "British Islands",
        "SurfaceArea": 193
    },
    "government": {
        "GovernmentForm": "Monarchy",
        "HeadOfState": "Michael Bates"
    }
}
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="document-store-concept-collection"></a>Collection</h3>

</div>

</div>

</div>
<p>
        A Collection is a container that may be used to store Documents
        in a MySQL database.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="document-store-concept-crud"></a>CRUD Operations</h3>

</div>

</div>

</div>
<p>
        Create, Read, Update and Delete (CRUD) operations are the four
        basic operations that can be performed on a database Collection
        or Table. In terms of MySQL this means:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            Create a new entry (insertion or addition)
          </p></li><li class="listitem"><p>
            Read entries (queries)
          </p></li><li class="listitem"><p>
            Update entries
          </p></li><li class="listitem"><p>
            Delete entries
</p></li></ul>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="document-store-concept-xplugin"></a>X Plugin</h3>

</div>

</div>

</div>
<p>
        The MySQL Server plugin which enables communication using
        X Protocol. Supports clients that implement X DevAPI
        and enables you to use MySQL as a document store.

        
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="document-store-concept-xprotocol"></a>X Protocol</h3>

</div>

</div>

</div>
<p>
        A protocol to communicate with a MySQL Server running
        X Plugin. X Protocol supports both CRUD and SQL
        operations, authentication via SASL, allows streaming
        (pipelining) of commands and is extensible on the protocol and
        the message layer.
</p>
</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="document-store-setting-up"></a>19.3 Setting Up MySQL as a Document Store</h2>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#document-store-shell-install">19.3.1 Installing MySQL Shell</a></span></dt><dt><span class="section"><a href="document-store.html#installing-mysql-shell-starting">19.3.2 Starting MySQL Shell</a></span></dt></dl>
</div>
<p>
    This section describes how to install the X Plugin to enable MySQL
    Server to use the X Protocol and use MySQL Shell to act as a
    client to the server.
  </p><p>
    The prerequisite for using MySQL as a document store is the
    X Plugin, which implements the X Protocol. Without the
    X Plugin running, X Protocol clients cannot connect to
    the server. The X Plugin is supplied with MySQL (5.7.12 or
    higher) — installing it does not involve a separate download.
  </p><p>
    Setting up MySQL as a document store follows the steps outlined
    here:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
        <span class="bold"><strong>Install or upgrade to MySQL 5.7.12 or
        higher.</strong></span>
      </p><p>
        When the <a class="link" href="installing.html" title="Chapter 2 Installing and Upgrading MySQL">installation</a> or
        upgrade is done, start the server. For server startup
        instructions, see <a class="xref" href="installing.html#starting-server" title="2.10.2 Starting the Server">Section 2.10.2, “Starting the Server”</a>.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
          MySQL Installer enables you to perform this and the next step
          (Install the X Plugin) at the same time for new
          installations on Microsoft Windows. In the <span class="guilabel">Plugin
          and Extensions</span> screen, check mark the
          <span class="guilabel">Enable X Protocol/MySQL as a Document
          Store</span> check box. After the installation, verify
          that the X Plugin has been installed.
</p>
</div>
</li><li class="listitem"><p><a name="installing-xplugin-linux-quick"></a>
        <span class="bold"><strong>Install the X Plugin.</strong></span> A
        non-root account can be used to install the plugin as long as
        the account has <a class="link" href="security.html#priv_insert"><code class="literal">INSERT</code></a> privilege
        for the <code class="literal">mysql.plugin</code> table.
      </p><p>
        Always save your existing configuration settings before
        reconfiguring the server.
      </p><p>
        To install the built-in X Plugin, do one of the following:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            Using <a class="link" href="installing.html#mysql-installer" title="2.3.3 MySQL Installer for Windows">MySQL Installer for
            Windows</a>:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="a"><li class="listitem"><p>
                Launch MySQL Installer for Windows. MySQL Installer
                dashboard opens.
              </p></li><li class="listitem"><p>
                Click the <span class="guilabel">Reconfigure</span> quick action
                for MySQL Server. Use <span class="guibutton">Next</span> and
                <span class="guibutton">Back</span> to configure the following
                items:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
                    In <span class="guilabel">Accounts and Roles</span>, confirm
                    the current <code class="literal">root</code> account
                    password.
                  </p></li><li class="listitem"><p>
                    In <span class="guilabel">Plugin and Extensions</span>, check
                    mark the <span class="guilabel">Enable X Protocol/MySQL as
                    a Document Store</span> check box. MySQL
                    Installer provides a default port number and opens
                    the firewall port for network access.
                  </p></li><li class="listitem"><p>
                    In <span class="guilabel">Apply Server Configuration</span>,
                    click <span class="guilabel">Execute</span>.
                  </p></li><li class="listitem"><p>
                    Click <span class="guibutton">Finish</span> to close MySQL
                    Installer.
</p></li></ul>
</div>
</li><li class="listitem"><p>
                <a class="link" href="document-store.html#installing-mysql-shell-windows-quick" title="19.3.1.1 Installing MySQL Shell on Microsoft Windows">Install
                MySQL Shell</a>.
</p></li></ol>
</div>
</li><li class="listitem"><p>
            Using MySQL Shell:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="a"><li class="listitem"><p>
                <a class="link" href="document-store.html#document-store-shell-install" title="19.3.1 Installing MySQL Shell">Install
                MySQL Shell</a>.
              </p></li><li class="listitem"><p>
                Open a terminal window (command prompt on Windows) and
                navigate to the MySQL binaries location (for example,
                <code class="filename">/usr/bin/</code> on Linux).
              </p></li><li class="listitem"><p>
                Run the following command:
              </p><pre data-lang="terminal" class="programlisting">
mysqlsh -u <em class="replaceable"><code>user</code></em> -h localhost --classic --dba enableXProtocol
</pre></li></ol>
</div>
</li><li class="listitem"><p>
            Using the MySQL Client program:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="a"><li class="listitem"><p>
                Open a terminal window (command prompt on Windows) and
                navigate to the MySQL binaries location (for example,
                <code class="filename">/usr/bin/</code> on Linux).
              </p></li><li class="listitem"><p>
                Invoke the <a class="link" href="programs.html#mysql" title="4.5.1 mysql — The MySQL Command-Line Tool"><span class="command"><strong>mysql</strong></span></a> command-line client:
              </p><pre data-lang="terminal" class="programlisting">
mysql -u <em class="replaceable"><code>user</code></em> -p
</pre></li><li class="listitem"><p>
                Issue the following statement:
              </p><pre data-lang="sql" class="programlisting">
mysql&gt; <strong class="userinput"><code>INSTALL PLUGIN mysqlx SONAME 'mysqlx.so';</code></strong>
</pre><p>
                Replace <code class="filename">mysqlx.so</code> with
                <code class="filename">mysqlx.dll</code> for Windows.
</p>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Important
</div>
<p>
                  The <code class="literal">mysql.session</code> user must exist
                  before you can load X Plugin.
                  <code class="literal">mysql.session</code> was added in MySQL
                  version 5.7.19. If your data dictionary was
                  initialized using an earlier version you must run the
                  <a class="link" href="programs.html#mysql-upgrade" title="4.4.7 mysql_upgrade — Check and Upgrade MySQL Tables"><span class="command"><strong>mysql_upgrade</strong></span></a> procedure. If the
                  upgrade is not run, X Plugin fails to start with
                  the error message <span class="errortext">There was an error when
                  trying to access the server with user:
                  mysql.session@localhost. Make sure the user is present
                  in the server and that mysql_upgrade was ran after a
                  server update.</span>.
</p>
</div>
</li><li class="listitem"><p>
                <a class="link" href="document-store.html#document-store-shell-install" title="19.3.1 Installing MySQL Shell">Install
                MySQL Shell</a>.
</p></li></ol>
</div>
</li></ul>
</div>
</li><li class="listitem"><p>
        <span class="bold"><strong>Verify that the X Plugin has been
        installed.</strong></span>
      </p><p>
        When the X Plugin is installed properly, it shows up in
        the list when you query for active plugins on the server with
        one of the following commands:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            MySQL Shell command:
          </p><pre data-lang="terminal" class="programlisting">
mysqlsh -u <em class="replaceable"><code>user</code></em> --sqlc -e "show plugins"
</pre></li><li class="listitem"><p>
            MySQL Client program command:
          </p><pre data-lang="terminal" class="programlisting">
mysql -u <em class="replaceable"><code>user</code></em> -p -e "show plugins"
</pre></li></ul>
</div>
<p>
        If you encounter problems with the X Plugin installation,
        or if you want to learn about alternative ways of installing,
        configuring, or uninstalling server plugins, see
        <a class="xref" href="server-administration.html#server-plugin-loading" title="5.5.1 Installing and Uninstalling Plugins">Section 5.5.1, “Installing and Uninstalling Plugins”</a>.
</p></li></ol>
</div>
<h3><a name="idm139684678852720"></a><code class="literal">mysqlxsys@localhost</code> User Account</h3>
<p>
    Installing the X Plugin creates a
    <code class="literal">mysqlxsys@localhost</code> user account. If, for some
    reason, creating the user account fails, the X Plugin
    installation fails, too. Here is an explanation on what the
    <code class="literal">mysqlxsys@localhost</code> user account is for and what
    to do when its creation fails.
  </p><p>
    The X Plugin installation process uses the MySQL
    <code class="literal">root</code> user to create an internal account for the
    <code class="literal">mysqlxsys@localhost</code> user. The
    <code class="literal">mysqlxsys@localhost</code> account is used by the
    X Plugin for authentication of external users against the
    MySQL account system and for killing sessions when requested by a
    privileged user. The <code class="literal">mysqlxsys@localhost</code> account
    is created as locked, so it cannot be used to log in by external
    users. If for some reason the MySQL <code class="literal">root</code> account
    is not available, before you start the X Plugin installation
    you must manually create the <code class="literal">mysqlxsys@localhost</code>
    user by issuing the following statements in the
    <a class="link" href="programs.html#mysql" title="4.5.1 mysql — The MySQL Command-Line Tool"><span class="command"><strong>mysql</strong></span></a> command-line client:
  </p><pre data-lang="sql" class="programlisting">
CREATE USER IF NOT EXISTS mysqlxsys@localhost IDENTIFIED WITH
mysql_native_password AS '<em class="replaceable"><code>password</code></em>' ACCOUNT LOCK;
GRANT SELECT ON mysql.user TO mysqlxsys@localhost;
GRANT SUPER ON *.* TO mysqlxsys@localhost;
</pre>
<h3><a name="idm139684678841360"></a>Uninstalling the X Plugin</h3>
<p>
    If you ever want to uninstall (deactivate) the X Plugin, issue
    the following statement in the <a class="link" href="programs.html#mysql" title="4.5.1 mysql — The MySQL Command-Line Tool"><span class="command"><strong>mysql</strong></span></a> command-line
    client:
  </p><pre data-lang="sql" class="programlisting">
UNINSTALL PLUGIN mysqlx;
</pre><p>
    Do not use MySQL Shell to issue the previous statement. It works
    from MySQL Shell, but you get an error (code 1130). Also,
    uninstalling the plugin removes the mysqlxsys user.
</p>
<div class="section">

<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="document-store-shell-install"></a>19.3.1 Installing MySQL Shell</h3>

</div>

</div>

</div>

<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#installing-mysql-shell-windows-quick">19.3.1.1 Installing MySQL Shell on Microsoft Windows</a></span></dt><dt><span class="section"><a href="document-store.html#installing-mysql-shell-linux-quick">19.3.1.2 Installing MySQL Shell on Linux</a></span></dt><dt><span class="section"><a href="document-store.html#installing-mysql-shell-osx-quick">19.3.1.3 Installing MySQL Shell on OS X</a></span></dt></dl>
</div>
<p>
      This section describes how to download, install, and start
      MySQL Shell, which is an interactive JavaScript, Python, or SQL
      interface supporting development and administration for the MySQL
      Server. MySQL Shell is a component that you can install
      separately.
</p>
<h4><a name="idm139684678835488"></a>Requirements</h4>
<p>
      MySQL Shell is available on Microsoft Windows, Linux, and OS X
      for 64-bit platforms. MySQL Shell requires that the built-in
      X Plugin be active. You can install the server plugin before
      or after you install MySQL Shell. For instructions, see
      <a class="link" href="document-store.html#installing-xplugin-linux-quick">Installing the
      X Plugin</a>.
</p>
<div class="section">

<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="installing-mysql-shell-windows-quick"></a>19.3.1.1 Installing MySQL Shell on Microsoft Windows</h4>

</div>

</div>

</div>

<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Important
</div>
<p>
          The Community version of MySQL Shell requires the Visual C++
          Redistributable for Visual Studio 2013 (available at the
          <a class="ulink" href="http://www.microsoft.com/en-us/download/default.aspx" target="_top">Microsoft
          Download Center</a>) to work; make sure that is installed
          on your Windows system before installing MySQL Shell.
</p>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
          MySQL Shell is currently not supplied with an MSI Installer.
          See <a class="xref" href="document-store.html#installing-mysql-shell-binaries" title="Installing MySQL Shell Binaries">Installing MySQL Shell Binaries</a> for the
          manual install procedure.
</p>
</div>
<p>
        To install MySQL Shell on Microsoft Windows using the MSI
        Installer, do the following:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
            Download the <span class="bold"><strong>Windows (x86, 64-bit),
            MSI Installer</strong></span> package from
            <a class="ulink" href="http://dev.mysql.com/downloads/shell/" target="_top">http://dev.mysql.com/downloads/shell/</a>.
          </p></li><li class="listitem"><p>
            When prompted, click <span class="guibutton">Run</span>.
          </p></li><li class="listitem"><p>
            Follow the steps in the Setup Wizard.
</p>
<div class="figure">
<a name="fig-x-installation-mysql-shell-win-quick"></a><p class="title"><b>Figure 19.1 Installation of MySQL Shell on Windows</b></p>
<div class="figure-contents">

<div class="mediaobject">
<img src="images/x-installation-mysql-shell-win.png" width="512" height="399" alt="Installation of MySQL Shell on Windows">
</div>

</div>

</div>
<br class="figure-break"></li></ol>
</div>
<p>
        If you have installed MySQL without enabling the X Plugin,
        then later on decide you want to install the X Plugin, or
        if you are installing MySQL <span class="emphasis"><em>without</em></span> using
        MySQL Installer, see
        <a class="link" href="document-store.html#installing-xplugin-linux-quick">Installing the
        X Plugin</a>.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="installing-mysql-shell-binaries"></a>Installing MySQL Shell Binaries</h5>
</div>
</div>
</div>
<p>
          To install MySQL Shell binaries:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
              Unzip the content of the Zip file to the MySQL products
              directory, for example <code class="filename">C:\Program
              Files\MySQL\</code>.
            </p></li><li class="listitem"><p>
              To be able to start MySQL Shell from a command prompt
              add the bin directory <code class="filename">C:\Program
              Files\MySQL\mysql-shell-1.0.8-rc-windows-x86-64bit\bin</code>
              to the <code class="literal">PATH</code> system variable.
</p></li></ol>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="installing-mysql-shell-linux-quick"></a>19.3.1.2 Installing MySQL Shell on Linux</h4>

</div>

</div>

</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
          Installation packages for MySQL Shell are available only for
          a limited number of Linux distributions, and only for 64-bit
          systems.
</p>
</div>
<p>
        For supported Linux distributions, the easiest way to install
        MySQL Shell on Linux is to use the
        <a class="ulink" href="http://dev.mysql.com/downloads/repo/apt/" target="_top">MySQL APT
        repository</a> or
        <a class="ulink" href="http://dev.mysql.com/downloads/repo/yum/" target="_top">MySQL Yum
        repository</a>. For systems not using the MySQL
        repositories, MySQL Shell can also be downloaded and installed
        directly.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="installing-mysql-shell-linux-apt"></a>Installing MySQL Shell with the MySQL APT Repository</h5>
</div>
</div>
</div>
<p>
          For Linux distributions supported by the
          <a class="ulink" href="http://dev.mysql.com/downloads/repo/apt/" target="_top">MySQL APT
          repository</a>, follow one of the paths below:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              If you do not yet have the
              <a class="ulink" href="http://dev.mysql.com/downloads/repo/apt/" target="_top">MySQL APT
              repository</a> as a software repository on your
              system, do the following:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
                  Follow the steps given in
                  <a class="ulink" href="http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/#apt-repo-setup" target="_top">Adding
                  the MySQL APT Repository</a>, paying special
                  attention to the following:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; "><li class="listitem"><p>
                      During the installation of the configuration
                      package, when asked in the dialogue box to
                      configure the repository, make sure you choose
                      MySQL 5.7 (which is the default option) as the
                      release series you want, and enable the
                      <span class="guimenuitem">MySQL Preview Packages</span>
                      component.
                    </p></li><li class="listitem"><p>
                      Make sure you do not skip the step for updating
                      package information for the MySQL APT repository:
</p><pre data-lang="terminal" class="programlisting"><strong class="userinput"><code>sudo apt-get update</code></strong></pre></li></ul>
</div>
</li><li class="listitem"><p>
                  Install MySQL Shell with this command:
                </p><pre data-lang="terminal" class="programlisting">
sudo apt-get install mysql-shell
</pre></li></ul>
</div>
</li><li class="listitem"><p>
              If you already have the
              <a class="ulink" href="http://dev.mysql.com/downloads/repo/apt/" target="_top">MySQL APT
              repository</a> as a software repository on your
              system, do the following:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
                  Update package information for the MySQL APT
                  repository:
                </p><pre data-lang="terminal" class="programlisting">
sudo apt-get update
</pre></li><li class="listitem"><p>
                  Update the MySQL APT repository configuration package
                  with the following command:
                </p><pre data-lang="terminal" class="programlisting">
sudo apt-get install mysql-apt-config
</pre><p>
                  When asked in the dialogue box to configure the
                  repository, make sure you choose MySQL 5.7 (which is
                  the default option) as the release series you want,
                  and enable the <span class="guimenuitem">MySQL Preview
                  Packages</span> component.
                </p></li><li class="listitem"><p>
                  Install MySQL Shell with this command:
                </p><pre data-lang="terminal" class="programlisting">
sudo apt-get install mysql-shell
</pre></li></ul>
</div>
</li></ul>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="installing-mysql-shell-linux-yum"></a>Installing MySQL Shell with the MySQL Yum Repository</h5>

</div>

</div>

</div>
<p>
          For Linux distributions supported by the
          <a class="ulink" href="http://dev.mysql.com/downloads/repo/yum/" target="_top">MySQL Yum
          repository</a>, follow these steps to install
          MySQL Shell:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              Do one of the following:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
                  If you already have the
                  <a class="ulink" href="http://dev.mysql.com/downloads/repo/yum/" target="_top">MySQL Yum
                  repository</a> as a software repository on your
                  system and the repository was configured with the new
                  release package
                  <code class="literal">mysql57-community-release</code>, skip to
                  the next step (<span class="quote">“<span class="quote">Enable the MySQL Tools Preview
                  subrepository...</span>”</span>).
                </p></li><li class="listitem"><p>
                  If you already have the
                  <a class="ulink" href="http://dev.mysql.com/downloads/repo/yum/" target="_top">MySQL Yum
                  repository</a> as a software repository on your
                  system but have configured the repository with the old
                  release package
                  <code class="literal">mysql-community-release</code>, it is
                  easiest to install MySQL Shell by first
                  reconfiguring the MySQL Yum repository with the new
                  <code class="literal">mysql57-community-release</code> package.
                  To do so, you need to remove your old release package
                  first, with the following command :
                </p><pre data-lang="terminal" class="programlisting">
sudo yum remove mysql-community-release
</pre><p>
                  For dnf-enabled systems, do this instead:
                </p><pre data-lang="terminal" class="programlisting">
sudo dnf erase mysql-community-release
</pre><p>
                  Then, follow the steps given in
                  <a class="ulink" href="http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-repo-setup" target="_top">Adding
                  the MySQL Yum Repository</a> to install the new
                  release package,
                  <code class="literal">mysql57-community-release</code>.
                </p></li><li class="listitem"><p>
                  If you do not yet have the
                  <a class="ulink" href="http://dev.mysql.com/downloads/repo/yum/" target="_top">MySQL Yum
                  repository</a> as a software repository on your
                  system, follow the steps given in
                  <a class="ulink" href="http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-repo-setup" target="_top">Adding
                  the MySQL Yum Repository</a>.
</p></li></ul>
</div>
</li><li class="listitem"><p>
              Enable the MySQL Tools Preview subrepository. You can do
              that by editing manually the
              <code class="filename">/etc/yum.repos.d/mysql-community.repo</code>
              file. This is an example of the subrepository's default
              entry in the file (the <code class="literal">baseurl</code> entry in
              your file might look different, depending on your Linux
              distribution):
            </p><pre data-lang="ini" class="programlisting">
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
</pre><p>
              Change the entry <code class="option">enabled=0</code> to
              <code class="option">enabled=1</code> to enable the subrepository.
            </p></li><li class="listitem"><p>
              Install MySQL Shell with this command:
            </p><pre data-lang="terminal" class="programlisting">
sudo yum install mysql-shell
</pre><p>
              For dnf-enabled systems, do this instead:
            </p><pre data-lang="terminal" class="programlisting">
sudo dnf install mysql-shell
</pre></li></ul>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="installing-mysql-shell-linux-direct"></a>Installing MySQL Shell from Direct Downloads from the MySQL Developer
Zone</h5>
</div>
</div>
</div>
<p>
          RPM, Debian, and source packages for installing MySQL Shell
          are also available for download at
          <a class="ulink" href="http://dev.mysql.com/downloads/shell/" target="_top">Download MySQL
          Shell</a>.
</p>
</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="installing-mysql-shell-osx-quick"></a>19.3.1.3 Installing MySQL Shell on OS X</h4>

</div>

</div>

</div>
<p>
        To install MySQL Shell on OS X, do the following:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
            Download the package from
            <a class="ulink" href="http://dev.mysql.com/downloads/shell/" target="_top">http://dev.mysql.com/downloads/shell/</a>.
          </p></li><li class="listitem"><p>
            Double-click the downloaded DMG to mount it. Finder opens.
          </p></li><li class="listitem"><p>
            Double-click the <code class="filename">.pkg</code> file shown in the
            Finder window.
          </p></li><li class="listitem"><p>
            Follow the steps in the installation wizard.
</p>
<div class="figure">
<a name="fig-x-installation-mysql-shell-osx-quick"></a><p class="title"><b>Figure 19.2 Installation of MySQL Shell on OS X</b></p>
<div class="figure-contents">

<div class="mediaobject">
<img src="images/x-installation-mysql-shell-osx-1.png" width="600" height="373" alt="Installation of MySQL Shell on OS X">
</div>

</div>

</div>
<br class="figure-break"></li><li class="listitem"><p>
            When the installer finishes, eject the DMG. (It can be
            deleted.)
</p></li></ol>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="installing-mysql-shell-starting"></a>19.3.2 Starting MySQL Shell</h3>

</div>

</div>

</div>
<p>
      You need an account name and password to establish a session using
      MySQL Shell. Replace <em class="replaceable"><code>user</code></em> with your
      account name.
    </p><p>
      On the same system where the server instance is running, open a
      terminal window (command prompt on Windows) and start MySQL Shell
      with the following command:

</p><pre data-lang="terminal" class="programlisting">
mysqlsh --uri <em class="replaceable"><code>user</code></em>@localhost
</pre><p>

      You are prompted to input your password and then this establishes
      an X Session.
    </p><p>
      For instructions to get you started using MySQL Shell and MySQL
      as a document store, see the following quick-start guides:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          <a class="link" href="document-store.html#mysql-shell-tutorial-javascript" title="19.5 Quick-Start Guide: MySQL Shell for JavaScript">Quick-Start
          Guide: MySQL Shell for JavaScript</a>
        </p></li><li class="listitem"><p>
          <a class="link" href="document-store.html#mysql-shell-tutorial-python" title="19.4 Quick-Start Guide: MySQL Shell for Python">Quick-Start Guide:
          MySQL Shell for Python</a>
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="mysql-shell-tutorial-python"></a>19.4 Quick-Start Guide: MySQL Shell for Python</h2>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-introduction">19.4.1 Introduction</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-download">19.4.2 Import Database Sample</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-shell">19.4.3 MySQL Shell</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-collections">19.4.4 Documents and Collections</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-relational-tables">19.4.5 Relational Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-in-tables">19.4.6 Documents in Tables</a></span></dt></dl>
</div>
<p>
    This quick-start guide provides instructions to begin prototyping
    database applications interactively with MySQL Shell. The guide
    includes the following topics:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Introduction to MySQL functionality, MySQL Shell, and the
        <code class="literal">world_x</code> database sample.
      </p></li><li class="listitem"><p>
        Operations to manage collections and documents.
      </p></li><li class="listitem"><p>
        Operations to manage relational tables.
      </p></li><li class="listitem"><p>
        Operations that apply to documents within tables.
</p></li></ul>
</div>
<h3><a name="idm139684678721008"></a>Available Quick-Start Guides</h3>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        <a class="link" href="document-store.html#mysql-shell-tutorial-javascript" title="19.5 Quick-Start Guide: MySQL Shell for JavaScript">MySQL Shell
        for JavaScript</a>
      </p></li><li class="listitem"><p>
        <a class="link" href="document-store.html#mysql-shell-visual-studio" title="19.6 Quick-Start Guide: MySQL for Visual Studio">MySQL for Visual
        Studio</a>
</p></li></ul>
</div>
<h3><a name="idm139684678716496"></a>Related Information</h3>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/" target="_top">MySQL Shell 8.0 (part of MySQL 8.0)</a> provides more in-depth information
        about MySQL Shell.
      </p></li><li class="listitem"><p>
        <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/" target="_top">X DevAPI User Guide</a> provides more examples of
        using X DevAPI.
</p></li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-python-introduction"></a>19.4.1 Introduction</h3>

</div>

</div>

</div>
<p>
      The MySQL Shell for Python quick start provides a short but
      comprehensive introduction to the database functionality including
      the new X DevAPI, which offers a modern, integrative way to
      work with relational and document data, without requiring SQL
      knowledge from application developers.
    </p><p>
      In MySQL, tables are the native data storage container type and
      collections are stored internally using tables.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h4 class="title"><a name="idm139684678709744"></a>JSON Documents and Collections</h4>
</div>
</div>
</div>
<p>
        A JSON
        <a class="link" href="document-store.html#mysql-shell-tutorial-python-documents" title="Documents">document</a>
        is a data structure composed of field/value pairs stored within
        a
        <a class="link" href="document-store.html#mysql-shell-tutorial-python-collections" title="19.4.4 Documents and Collections">collection</a>.
        The values of fields often contain other documents, arrays, and
        lists of documents.
      </p><pre class="programlisting">
{
    "GNP": .6,
    "IndepYear": 1967,
    "Name": "Sealand",
    "_id": "SEA",
    "demographics": {
        "LifeExpectancy": 79,
        "Population": 27
    },
    "geography": {
        "Continent": "Europe",
        "Region": "British Islands",
        "SurfaceArea": 193
    },
    "government": {
        "GovernmentForm": "Monarchy",
        "HeadOfState": "Michael Bates"
    }
}
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678705184"></a>Relational Tables</h4>

</div>

</div>

</div>
<p>
        A
        <a class="link" href="document-store.html#mysql-shell-tutorial-python-relational-tables" title="19.4.5 Relational Tables">table</a>
        in MySQL enables you to store data organized in rows and
        columns. The structure of a table is defined by one or more
        columns with user-defined names and data types. Every row stored
        in the table has the same structure.
      </p><pre class="programlisting">
+------+------------------+-------------+-----------------+------------------------+
| ID   | Name             | CountryCode | District        | Info                   |
+------+------------------+-------------+-----------------+------------------------+
|    1 | Kabul            | AFG         | Kabol           |{"Population": 1780000} |
|    2 | Qandahar         | AFG         | Qandahar        |{"Population": 237500}  |
|    3 | Herat            | AFG         | Herat           |{"Population": 186800}  |
|    4 | Mazar-e-Sharif   | AFG         | Balkh           |{"Population": 127800}  |
|    5 | Amsterdam        | NLD         | Noord-Holland   |{"Population": 731200}  |
|    6 | Rotterdam        | NLD         | Zuid-Holland    |{"Population": 593321}  |
+------+------------------+-------------+-----------------+------------------------+
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678701120"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/" target="_top">MySQL Shell 8.0 (part of MySQL 8.0)</a> provides a general overview.
          </p></li><li class="listitem"><p>
            See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/" target="_top">X DevAPI User Guide</a> for development
            reference documentation.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-python-download"></a>19.4.2 Import Database Sample</h3>

</div>

</div>

</div>
<p>
      The <code class="literal">world_x</code> database sample contains one JSON
      collection and a set of three relational tables:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Collection
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
              countryinfo: Information about countries in the world.
</p></li></ul>
</div>
</li><li class="listitem"><p>
          Tables
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
              country: Minimal information about countries of the world.
            </p></li><li class="listitem"><p>
              city: Information about some of the cities in those
              countries.
            </p></li><li class="listitem"><p>
              countrylanguage: Languages spoken in each country.
</p></li></ul>
</div>
</li></ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678688032"></a>Requirements</h4>

</div>

</div>

</div>
<p>
        You must install MySQL Shell with the X Protocol
        enabled. For instructions, see
        <a class="xref" href="document-store.html#document-store-setting-up" title="19.3 Setting Up MySQL as a Document Store">Section 19.3, “Setting Up MySQL as a Document Store”</a>.
      </p><p>
        Start the server before you load the <code class="literal">world_x</code>
        database for this guide.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678684768"></a>Download world_x Database</h4>

</div>

</div>

</div>
<p>
        To prepare the <code class="literal">world_x</code> database sample,
        follow these steps:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
            Download
            <a class="ulink" href="http://downloads.mysql.com/docs/world_x-db.zip" target="_top">world_x-db.zip</a>.
          </p></li><li class="listitem"><p>
            Extract the installation archive to a temporary location
            such as <code class="filename">/tmp/</code>. Unpacking the archive
            results in a single file named
            <code class="filename">world_x.sql</code>.
          </p></li><li class="listitem"><p>
            Create the schema with the following command:
          </p><pre class="programlisting">
<strong class="userinput"><code>mysqlsh -u root --sql &lt; /tmp/world_x-db/world_x.sql</code></strong>
Enter password: <strong class="userinput"><code>****</code></strong>
</pre><p>
            Enter your password when prompted. A non-root account can be
            used as long as the account has privileges to create new
            databases.
          </p><p>
            Replace <code class="filename">/tmp/</code> with the path to the
            <code class="filename">world_x.sql</code> file on your system.
</p></li></ol>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678672432"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-sessions.html" target="_top">MySQL Shell Sessions</a> explains session
            types.
          </p></li><li class="listitem"><p>
            See <a class="xref" href="installing.html" title="Chapter 2 Installing and Upgrading MySQL">Chapter 2, <i>Installing and Upgrading MySQL</i></a> for general installation
            assistance.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-python-shell"></a>19.4.3 MySQL Shell</h3>

</div>

</div>

</div>
<p>
      MySQL Shell is a unified scripting interface to MySQL Server. It
      supports scripting in JavaScript and Python. JavaScript is the
      default processing mode. In most cases, you need an account to
      connect to the local MySQL server instance.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h4 class="title"><a name="mysql-shell-tutorial-python-shell-start"></a>Start MySQL Shell</h4>
</div>
</div>
</div>
<p>
        After you have installed and started MySQL server, connect
        MySQL Shell to the server instance. By default, MySQL Shell
        connects using the X Protocol.
      </p><p>
        On the same system where the server instance is running, open a
        terminal window and start MySQL Shell with the following
        command:
      </p><pre class="programlisting">
<strong class="userinput"><code>mysqlsh <em class="replaceable"><code>name</code></em>@localhost/world_x</code></strong> --py
Creating a Session to <em class="replaceable"><code>name</code></em>@localhost/world_x
Enter password:<strong class="userinput"><code> ****</code></strong>
</pre><p>
        You may need to specify the path as appropriate.
      </p><p>
        In addition:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <em class="replaceable"><code>name</code></em> represents the user name of
            your MySQL account.
          </p></li><li class="listitem"><p>
            MySQL Shell prompts you for your password.
          </p></li><li class="listitem"><p>
            The <code class="literal">--py</code> option starts MySQL Shell in
            Python mode. If you omit <code class="literal">--py</code>,
            MySQL Shell starts in JavaScript mode.
          </p></li><li class="listitem"><p>
            The default schema for this session is the
            <code class="literal">world_x</code> database. For instructions on
            setting up the <code class="literal">world_x</code> database sample,
            see <a class="xref" href="document-store.html#mysql-shell-tutorial-python-download" title="19.4.2 Import Database Sample">Section 19.4.2, “Import Database Sample”</a>.
</p></li></ul>
</div>
<p>
        The <code class="literal">mysql-py&gt;</code> prompt indicates that the
        active language for this session is Python.
      </p><pre class="programlisting">
mysql-py&gt;
</pre><p>
        When you run <span class="command"><strong>mysqlsh</strong></span> without the host
        argument, MySQL Shell attempts to connect to the server
        instance running on the localhost interface on port 33060. To
        specify a different host or port number, as well as other
        options, see the option descriptions at
        <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysqlsh.html" target="_top"><span class="command"><strong>mysqlsh</strong></span> — The MySQL Shell</a>.
      </p><p>
        MySQL Shell supports input-line editing as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <span class="keycap"><strong>left-arrow</strong></span> and <span class="keycap"><strong>right-arrow</strong></span>
            keys move horizontally within the current input line.
          </p></li><li class="listitem"><p>
            <span class="keycap"><strong>up-arrow</strong></span> and <span class="keycap"><strong>down-arrow</strong></span>
            keys move up and down through the set of previously entered
            lines.
          </p></li><li class="listitem"><p>
            <span class="keycap"><strong>Backspace</strong></span> deletes the character before the
            cursor and typing new characters enters them at the cursor
            position.
          </p></li><li class="listitem"><p>
            <span class="keycap"><strong>Enter</strong></span> enters the current input line.
</p></li></ul>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="mysql-shell-tutorial-python-shell-help"></a>Get Help for MySQL Shell</h4>

</div>

</div>

</div>
<p>
        Type <span class="command"><strong>mysqlsh --help</strong></span> at the prompt of your
        command interpreter for a list of command-line options.
      </p><pre class="programlisting">
<strong class="userinput"><code>mysqlsh --help</code></strong>
</pre><p>
        Type <code class="literal">\help</code> at the MySQL Shell prompt for a
        list of available commands and their descriptions.
      </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>\help</code></strong>
</pre><p>
        Type <code class="literal">\help</code> followed by a command name for
        detailed help about an individual MySQL Shell command. For
        example, to view help on the <code class="literal">\connect</code>
        command, type:
      </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>\help \connect</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="mysql-shell-tutorial-python-shell-quit"></a>Quit MySQL Shell</h4>

</div>

</div>

</div>
<p>
        To quit MySQL Shell, type the following command:
      </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>\quit</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678625584"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            See <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-interactive-code-execution.html" target="_top">Interactive Code Execution</a>
            for an explanation of how interactive code execution works
            in MySQL Shell.
          </p></li><li class="listitem"><p>
            See <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-getting-started.html" target="_top">Getting Started with MySQL Shell</a> to learn
            about session and connection alternatives.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-python-collections"></a>19.4.4 Documents and Collections</h3>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-collections-operations">19.4.4.1 Create, List, and Drop Collections</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-add">19.4.4.2 Add Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-find">19.4.4.3 Find Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-modify">19.4.4.4 Modify Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-remove">19.4.4.5 Remove Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-documents-index">19.4.4.6 Create and Drop Indexes</a></span></dt></dl>
</div>
<p>
      In MySQL, collections contain JSON documents that you can add,
      find, update, and remove. Collections are containers within a
      schema that you create, list, and drop.
    </p><p>
      The examples in this section use the countryinfo collection in the
      <code class="literal">world_x</code> database. For instructions on setting
      up the <code class="literal">world_x</code> database sample, see
      <a class="xref" href="document-store.html#mysql-shell-tutorial-python-download" title="19.4.2 Import Database Sample">Section 19.4.2, “Import Database Sample”</a>.
</p>
<h4><a name="mysql-shell-tutorial-python-documents"></a>Documents</h4>
<p>
      In MySQL, documents are represented as JSON objects. Internally,
      they are stored in an efficient binary format that enables fast
      lookups and updates.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Simple document format for Python:
        </p><pre class="screen">
{"field1": "value", "field2" : 10, "field 3": null}
</pre></li></ul>
</div>
<p>
      An array of documents consists of a set of documents separated by
      commas and enclosed within <code class="literal">[</code> and
      <code class="literal">]</code> characters.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Simple array of documents for Python:
        </p><pre class="screen">
[{"Name": "Aruba", "_id": "ABW"}, {"Name": "Angola", "_id": "AGO"}]
</pre></li></ul>
</div>
<p>
      MySQL supports the following Python value types in JSON documents:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          numbers (integer and floating point)
        </p></li><li class="listitem"><p>
          strings
        </p></li><li class="listitem"><p>
          boolean (False and True)
        </p></li><li class="listitem"><p>
          None
        </p></li><li class="listitem"><p>
          arrays of more JSON values
        </p></li><li class="listitem"><p>
          nested (or embedded) objects of more JSON values
</p></li></ul>
</div>
<h4><a name="mysql-shell-tutorial-python-collections-details"></a>Collections</h4>
<p>
      Collections are containers for documents that share a purpose and
      possibly share one or more indexes. Each collection has a unique
      name and exists within a single schema.
    </p><p>
      The term schema is equivalent to a database, which means a group
      of database objects (as opposed to relational schema used to
      enforce structure and constraints over data). A schema does not
      enforce conformity on the documents in a collection.
    </p><p>
      In this quick-start guide:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Basic objects include:
</p>
<div class="informaltable">
<table summary="Objects to use interactively in MySQL Shell"><col width="40%"><col width="70%"><thead><tr>
              <th scope="col">Object form</th>
              <th scope="col">Description</th>
            </tr></thead><tbody><tr>
              <td scope="row"><code class="literal">db</code></td>
              <td><code class="literal">db</code> is a global variable assigned to the current
                active schema that you specified on the command line.
                You can type <code class="literal">db</code> in MySQL Shell to
                print a description of the object, which in this case
                will be the name of the schema it represents.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.get_collections()</code></td>
              <td><a class="link" href="document-store.html#mysql-shell-tutorial-python-collections-get" title="List Collections">db.get_collections()</a>
                holds a list of collections in the schema. Use the list
                to get references to collection objects, iterate over
                them, and so on.</td>
</tr></tbody></table>
</div>
</li><li class="listitem"><p>
          Basic operations scoped by collections include:
</p>
<div class="informaltable">
<table summary="CRUD operations to use interactively on documents in MySQL Shell"><col width="40%"><col width="70%"><thead><tr>
              <th scope="col">Operation form</th>
              <th scope="col">Description</th>
            </tr></thead><tbody><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.add()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-python-documents-add" title="19.4.4.2 Add Documents">add()</a>
                method inserts one document or a list of documents into
                the named collection.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.find()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-python-documents-find" title="19.4.4.3 Find Documents">find()</a>
                method returns some or all documents in the named
                collection.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.modify()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-python-documents-modify" title="19.4.4.4 Modify Documents">modify()</a>
                method updates documents in the named collection.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.remove()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-python-documents-remove" title="19.4.4.5 Remove Documents">remove()</a>
                method deletes one document or a list of documents from
                the named collection.</td>
</tr></tbody></table>
</div>
</li></ul>
</div>
<h4><a name="idm139684678561312"></a>Related Information</h4>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-collections.html" target="_top">Working with Collections</a>
          for a general overview.
        </p></li><li class="listitem"><p>
          <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/mysql-x-crud-ebnf-definitions.html" target="_top">CRUD EBNF Definitions</a> provides a
          complete list of operations.
</p></li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-collections-operations"></a>19.4.4.1 Create, List, and Drop Collections</h4>

</div>

</div>

</div>
<p>
        In MySQL Shell, you can create new collections, get a list of
        the existing collections in a schema, and remove an existing
        collection from a schema. Collection names are case-sensitive
        and each collection name must be unique.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678555088"></a>Confirm the Schema</h5>
</div>
</div>
</div>
<p>
          To show the value that is assigned to the schema variable,
          type <code class="literal">db</code>.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db</code></strong>
</pre><p>
          If the schema value is not <code class="literal">Schema:world_x</code>,
          then set the <code class="literal">db</code> variable as follows:
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>\use world_x</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-python-collections-create"></a>Create a Collection</h5>

</div>

</div>

</div>
<p>
          To create a new collection in an existing schema, use the
          <code class="literal">create_collection()</code> method. The following
          example creates in the <code class="literal">world_x</code> database a
          collection called flags.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.create_collection("flags")</code></strong>
</pre><p>
          The method returns a collection object.
</p><pre class="screen">&lt;Collection:flags&gt;</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-python-collections-get"></a>List Collections</h5>

</div>

</div>

</div>
<p>
          To display all collections in the <code class="literal">world_x</code>
          database, use the <code class="literal">get_collections()</code> method
          on the schema object. Collections returned by the server
          appear between brackets.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.get_collections()</code></strong>
[
    &lt;Collection:countryinfo&gt;,
    &lt;Collection:flags&gt;
]
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-python-collections-drop"></a>Drop a Collection</h5>

</div>

</div>

</div>
<p>
          To drop an existing collection from a database, use the
          <code class="literal">drop_collection()</code> method on the session
          object. For example, to drop the flags collection from the
          <code class="literal">world_x</code> database, type:
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>session.drop_collection("world_x", "flags")</code></strong>
Query OK (0.04 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678533120"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See
              <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-connections-in-javascript-and-python.html" target="_top">Connections in JavaScript and Python</a>
              to learn more about the session object.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/collection-objects.html" target="_top">Collection Objects</a> for more
              examples.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-documents-add"></a>19.4.4.2 Add Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">add()</code> method to insert one
        document or a list documents into an existing collection using
        MySQL Shell. All examples in this section use the countryinfo
        collection.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678525968"></a>Confirm the Schema</h5>
</div>
</div>
</div>
<p>
          To show the value that is assigned to the schema variable,
          type<code class="literal">db</code>.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db</code></strong>
</pre><p>
          If the schema value is not <code class="literal">Schema:world_x</code>,
          then set the <code class="literal">db</code> variable as follows:
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>\use world_x</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678519408"></a>Add a Document</h5>

</div>

</div>

</div>
<p>
          Insert the following document into the countryinfo collection.
          Press <span class="keycap"><strong>Enter</strong></span> twice to insert the document.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.add(
 {
    "GNP": .6,
    "IndepYear": 1967,
    "Name": "Sealand",
    "_id": "SEA",
    "demographics": {
        "LifeExpectancy": 79,
        "Population": 27
    },
    "geography": {
        "Continent": "Europe",
        "Region": "British Islands",
        "SurfaceArea": 193
    },
    "government": {
        "GovernmentForm": "Monarchy",
        "HeadOfState": "Michael Bates"
    }
  }
)</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre><p>
          The method returns the status of the operation.
        </p><p>
          Each document requires an identifier field called
          <code class="literal">_id</code>. The value of the
          <code class="literal">_id</code> field must be unique among all
          documents in the same collection. If the document passed to
          the <code class="literal">add()</code> method does not contain the
          <code class="literal">_id</code> field, MySQL Shell automatically
          inserts a field into the document and sets the value to a
          generated universal unique identifier (UUID).
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678511520"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionaddfunction" target="_top">CollectionAddFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-documents-find"></a>19.4.4.3 Find Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">find()</code> method to query for
        and return documents from a collection in a database.
        MySQL Shell provides additional methods to use with the
        <code class="literal">find()</code> method to filter and sort the returned
        documents.
      </p><p>
        MySQL provides the following operators to specify search
        conditions: <code class="literal">OR</code> (<code class="literal">||</code>),
        <code class="literal">AND</code> (<code class="literal">&amp;&amp;</code>),
        <code class="literal">XOR</code>, <code class="literal">IS</code>,
        <code class="literal">NOT</code>, <code class="literal">BETWEEN</code>,
        <code class="literal">IN</code>, <code class="literal">LIKE</code>,
        <code class="literal">!=</code>, <code class="literal">&lt;&gt;</code>,
        <code class="literal">&gt;</code>, <code class="literal">&gt;=</code>,
        <code class="literal">&lt;</code>, <code class="literal">&lt;=</code>,
        <code class="literal">&amp;</code>, <code class="literal">|</code>,
        <code class="literal">&lt;&lt;</code>, <code class="literal">&gt;&gt;</code>,
        <code class="literal">+</code>, <code class="literal">-</code>,
        <code class="literal">*</code>, <code class="literal">/</code>,
        <code class="literal">~</code>, and <code class="literal">%</code>.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-python-documents-find-all"></a>Find All Documents in a Collection</h5>
</div>
</div>
</div>
<p>
          To return all documents in a collection, use the
          <code class="literal">find()</code> method without specifying search
          conditions. For example, the following operation returns all
          documents in the countryinfo collection.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find()</code></strong>
[
     {
          "GNP": 828,
          "IndepYear": null,
          "Name": "Aruba",
          "_id": "ABW",
          "demographics": {
              "LifeExpectancy": 78.4000015258789,
              "Population": 103000
          },
          "geography": {
              "Continent": "North America",
              "Region": "Caribbean",
              "SurfaceArea": 193
          },
          "government": {
              "GovernmentForm": "Nonmetropolitan Territory of The Netherlands",
              "HeadOfState": "Beatrix"
          }
          ...
      }
 ]
240 documents in set (0.00 sec)
</pre><p>
          The method produces results that contain operational
          information in addition to all documents in the collection.
        </p><p>
          An empty set (no matching documents) returns the following
          information:
        </p><pre class="screen">
Empty set (0.00 sec) 
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678480624"></a>Filter Searches</h5>

</div>

</div>

</div>
<p>
          You can include search conditions with the
          <code class="literal">find()</code> method. The syntax for expressions
          that form a search condition is the same as that of
          traditional <a class="link" href="functions.html" title="Chapter 12 Functions and Operators">MySQL</a>. You must
          enclose all expressions in quotes.
        </p><p>
          All examples in this section use the countryinfo collection in
          the <code class="literal">world_x</code> database. For the sake of
          brevity, some of the examples do not display output.
        </p><p>
          A simple search condition consists of the
          <code class="literal">_id</code> field and unique identifier of a
          document. The following example returns a single document
          matching the identifier string:
        </p><pre class="programlisting">
<strong class="userinput"><code>mysql-py&gt; db.countryinfo.find("_id = 'AUS'")</code></strong>
[
    {
        "GNP": 351182,
        "IndepYear": 1901,
        "Name": "Australia",
        "_id": "AUS",
        "demographics": {
            "LifeExpectancy": 79.80000305175781,
            "Population": 18886000
        },
        "geography": {
            "Continent": "Oceania",
            "Region": "Australia and New Zealand",
            "SurfaceArea": 7741220
        },
        "government": {
            "GovernmentForm": "Constitutional Monarchy, Federation",
            "HeadOfState": "Elisabeth II"
        }
    }
]
1 document in set (0.01 sec)
</pre><p>
          The following example searches for all countries that have a
          GNP higher than $500 billion. The countryinfo collection
          measures GNP in units of million.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find("GNP &gt; 500000")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
10 documents in set (0.00 sec)
</pre><p>
          The Population field in the following query is embedded within
          the demographics object. To access the embedded field, use a
          period between demographics and Population to identify the
          relationship. Document and field names are case-sensitive.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find("GNP &gt; 500000 and demographics.Population &lt; 100000000")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
6 documents in set (0.00 sec)
</pre><p>
          Arithmetic operators in the following expression are used to
          query for countries with a GNP per capita higher than $30000.
          Search conditions can include arithmetic operators and most
          MySQL functions.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
            Seven documents in the countryinfo collection have a
            population value of zero. Warning messages appear at the end
            of the output.
</p>
</div>
<pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find("GNP*1000000/demographics.Population &gt; 30000")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
9 documents in set, 7 warnings (0.00 sec)
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
</pre><p>
          You can separate a value from the search condition by using
          the <code class="literal">bind()</code> method. For example, instead of
          specifying a hard-coded country name as the condition,
          substitute a named placeholder consisting of a colon followed
          by a name that begins with a letter, such as
          <span class="emphasis"><em>country</em></span>. Then include the placeholder and
          value in the <code class="literal">bind()</code> method as follows:
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find("Name = :country").bind("country", "Italy")</code></strong>
[
    {
        "GNP": 1161755,
        "IndepYear": 1861,
        "Name": "Italy",
        "_id": "ITA",
        "demographics": {
            "LifeExpectancy": 79,
            "Population": 57680000
        },
        "geography": {
            "Continent": "Europe",
            "Region": "Southern Europe",
            "SurfaceArea": 301316
        },
        "government": {
            "GovernmentForm": "Republic",
            "HeadOfState": "Carlo Azeglio Ciampi"
        }
    }
]
1 document in set (0.01 sec)
</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Tip
</div>
<p>
            Within a program, binding enables you to specify
            placeholders in your expressions, which are filled in with
            values before execution and can benefit from automatic
            escaping, as appropriate.
          </p><p>
            Always use binding to sanitize input. Avoid introducing
            values in queries using string concatenation, which can
            produce invalid input and, in some cases, can cause security
            issues.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678457664"></a>Project Results</h5>

</div>

</div>

</div>
<p>
          You can return specific fields of a document, instead of
          returning all the fields. The following example returns the
          GNP and Name fields of all documents in the countryinfo
          collection matching the search conditions.
        </p><p>
          Use the <code class="literal">fields()</code> method to pass the list of
          fields to return.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find("GNP &gt; 5000000").fields(["GNP", "Name"])</code></strong>
[
    {
        "GNP": 8510700,
        "Name": "United States"
    }
]
1 document in set (0.00 sec)
 </pre><p>
          In addition, you can alter the returned
          documents—adding, renaming, nesting and even computing
          new field values—with an expression that describes the
          document to return. For example, alter the names of the fields
          with the following expression to return only two documents.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find().\
fields(mysqlx.expr('{"Name": upper(Name), "GNPPerCapita": GNP*1000000/demographics.Population}')).\
limit(2)</code></strong>
[
    {
        "GNPPerCapita": 8038.834951456311,
        "Name": "ARUBA"
    },
    {
        "GNPPerCapita": 263.0281690140845,
        "Name": "AFGHANISTAN"
    }
]
2 documents in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678450576"></a>Limit, Sort, and Skip Results</h5>

</div>

</div>

</div>
<p>
          You can apply the <code class="literal">limit()</code>,
          <code class="literal">sort()</code>, and <code class="literal">skip()</code>
          methods to manage the number and order of documents returned
          by the <code class="literal">find()</code> method.
        </p><p>
          To specify the number of documents included in a result set,
          append the <code class="literal">limit()</code> method with a value to
          the <code class="literal">find()</code> method. The following query
          returns the first five documents in the countryinfo
          collection.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find().limit(5)</code></strong>
... [<span class="emphasis"><em>output removed</em></span>]
5 documents in set (0.00 sec)
</pre><p>
          To specify an order for the results, append the
          <code class="literal">sort()</code> method to the
          <code class="literal">find()</code> method. Pass to the
          <code class="literal">sort()</code> method a list of one or more fields
          to sort by and, optionally, the descending
          (<code class="literal">desc</code>) or ascending
          (<code class="literal">asc</code>) attribute as appropriate. Ascending
          order is the default order type.
        </p><p>
          For example, the following query sorts all documents by the
          IndepYear field and then returns the first eight documents in
          descending order.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find().sort(["IndepYear desc"]).limit(8)</code></strong>
... [<span class="emphasis"><em>output removed</em></span>]
8 documents in set (0.00 sec)
</pre><p>
          By default, the <code class="literal">limit()</code> method starts from
          the first document in the collection. You can use the
          <code class="literal">skip()</code> method to change the starting
          document. For example, to ignore the first document and return
          the next eight documents matching the condition, pass to the
          <code class="literal">skip()</code> method a value of 1.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1)</code></strong>
... [<span class="emphasis"><em>output removed</em></span>]
8 documents in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678430928"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              The <a class="link" href="functions.html" title="Chapter 12 Functions and Operators">MySQL Reference
              Manual</a> provides detailed documentation on functions
              and operators.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionfindfunction" target="_top">CollectionFindFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-documents-modify"></a>19.4.4.4 Modify Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">modify()</code> method to update one
        or more documents in a collection. The X DevAPI provides
        additional methods for use with the <code class="literal">modify()</code>
        method to:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            Set and unset fields within documents.
          </p></li><li class="listitem"><p>
            Append, insert, and delete arrays.
          </p></li><li class="listitem"><p>
            Bind, limit, and sort the documents to be modified.
</p></li></ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678420048"></a>Set and Unset Fields</h5>

</div>

</div>

</div>
<p>
          The <code class="literal">modify()</code> method works by filtering a
          collection to include only the documents to be modified and
          then applying the operations that you specify to those
          documents.
        </p><p>
          In the following example, the <code class="literal">modify()</code>
          method uses the search condition to identify the document to
          change and then the <code class="literal">set()</code> method replaces
          two values within the nested demographics object.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.modify("_id = 'SEA'").\
set("demographics", {"LifeExpectancy": 78, "Population": 28})</code></strong>
Query OK, 1 item affected (0.04 sec)
</pre><p>
          After you modify a document, use the <code class="literal">find()</code>
          method to verify the change.
        </p><p>
          To remove content from a document, use the
          <code class="literal">modify()</code> and <code class="literal">unset()</code>
          methods. For example, the following query removes the GNP from
          a document that matches the search condition.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'Sealand'").unset("GNP")</code></strong>
Query OK, 1 item affected (0.01 sec)   
</pre><p>
          Use the <code class="literal">find()</code> method to verify the change.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.find("Name = 'Sealand'")</code></strong>
[
    {
        "IndepYear": 1967,
        "Name": "Sealand",
        "_id": "SEA",
        "demographics": {
            "LifeExpectancy": 78,
            "Population": 28
        },
        "geography": {
            "Continent": "Europe",
            "Region": "British Islands",
            "SurfaceArea": 193
        },
        "government": {
            "GovernmentForm": "Monarchy",
            "HeadOfState": "Michael Bates"
        }
    }
]
1 document in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678406720"></a>Append, Insert, and Delete Arrays</h5>

</div>

</div>

</div>
<p>
          To append an element to an array field, or insert, or delete
          elements in an array, use the
          <code class="literal">array_append()</code>,
          <code class="literal">array_insert()</code>, or
          <code class="literal">array_delete()</code> methods. The following
          examples modify the countryinfo collection to enable tracking
          of international airports.
        </p><p>
          The first example uses the <code class="literal">modify()</code> and
          <code class="literal">set()</code> methods to create a new Airports
          field in all documents.
</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Caution
</div>
<p>
            Use care when you modify documents without specifying a
            search condition. This action will modify all documents in
            the collection.
</p>
</div>
<pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.modify("True").set("Airports", [])</code></strong>
Query OK, 240 items affected (0.07 sec)
</pre><p>
          With the Airports field added, the next example uses the
          <code class="literal">array_append()</code> method to add a new airport
          to one of the documents. <span class="emphasis"><em>$.Airports</em></span> in
          the following example represents the Airports field of the
          current document.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'France'").array_append("$.Airports", "ORY")</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre><p>
          Use <strong class="userinput"><code>db.countryinfo.find("Name =
          'France'")</code></strong> to see the change.
        </p><p>
          To insert an element at a different position in the array, use
          the <code class="literal">array_insert()</code> method to specify which
          index to insert in the path expression. In this case, the
          index is 0, or the first element in the array.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'France'").array_insert("$.Airports[0]", "CDG")</code></strong>
Query OK, 1 item affected (0.04 sec)
</pre><p>
          To delete an element from the array, you must pass to the
          <code class="literal">array_delete()</code> method the index of the
          element to be deleted.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'France'").array_delete("$.Airports[1]")</code></strong>
Query OK, 1 item affected (0.03 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678388688"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              The <a class="link" href="data-types.html#json-paths" title="Searching and Modifying JSON Values">MySQL Reference
              Manual</a> provides instructions to help you search for
              and modify JSON values.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionmodifyfunction" target="_top">CollectionModifyFunction</a>
              for the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-documents-remove"></a>19.4.4.5 Remove Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">remove()</code> method to delete
        some or all documents from a collection in a database. The
        X DevAPI provides additional methods for use with the
        <code class="literal">remove()</code> method to filter and sort the
        documents to be removed.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678380656"></a>Remove Documents Using Conditions</h5>
</div>
</div>
</div>
<p>
          The example that follows passes a search condition to the
          <code class="literal">remove()</code> method. All documents matching the
          condition will be removed from the countryinfo collection. In
          this example, one document matches the condition.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.remove("_id = 'SEA'")</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678377040"></a>Remove the First Document</h5>

</div>

</div>

</div>
<p>
          To remove the first document in the countryinfo collection,
          use the <code class="literal">limit()</code> method with a value of 1.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.remove("True").limit(1)</code></strong>
Query OK, 1 item affected (0.03 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678373552"></a>Remove the Last Document in an Order</h5>

</div>

</div>

</div>
<p>
          The following example removes the last document in the
          countryinfo collection by country name.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.countryinfo.remove("True").sort(["Name desc"]).limit(1)</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678370736"></a>Remove All Documents in a Collection</h5>

</div>

</div>

</div>
<p>
          You can remove all documents in a collection. To do so, use
          the <code class="literal">remove("True")</code> method without
          specifying a search condition.
</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Caution
</div>
<p>
            Use care when you remove documents without specifying a
            search condition. This action will delete all documents from
            the collection.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678367712"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionremovefunction" target="_top">CollectionRemoveFunction</a>
              for the full syntax definition.
            </p></li><li class="listitem"><p>
              See <a class="xref" href="document-store.html#mysql-shell-tutorial-python-download" title="19.4.2 Import Database Sample">Section 19.4.2, “Import Database Sample”</a>
              for instructions to recreate the
              <code class="literal">world_x</code> database.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-documents-index"></a>19.4.4.6 Create and Drop Indexes</h4>

</div>

</div>

</div>
<p>
        Indexes are used to find documents with specific field values
        quickly. Without an index, MySQL must begin with the first
        document and then read through the entire collection to find the
        relevant fields. The larger the collection, the more this costs.
        If a collection is large and queries on a specific field are
        common, then consider creating an index on a specific field
        inside a document.
      </p><p>
        For example, the following query will perform better with an
        index:
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("demographics.Population &lt; 100")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
8 documents in set (0.00 sec)
</pre><p>
        The <code class="literal">create_index()</code> method creates an index
        that you can define as nonunique or unique. Use the
        <code class="literal">field()</code> method to chain the fields that
        should be indexed. The <code class="literal">execute()</code> method is
        required to create or drop an index.
      </p><p>
        In MySQL, the <code class="literal">_id</code> field is equivalent to a
        primary key by default.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678354080"></a>Add a Nonunique Index</h5>
</div>
</div>
</div>
<p>
          To create a nonunique index, pass to the
          <code class="literal">create_index()</code> method an index name.
          Duplicate index names are prohibited.
        </p><p>
          In the following example, the first parameter of the
          <code class="literal">field()</code> method specifies the Population
          field inside the demographics object and the next parameter
          indicates that the field should be indexed as an Integer
          numeric value. The last parameter indicates whether the field
          should require the NOT NULL constraint. If the value is
          <code class="literal">False</code>, the field can contain
          <code class="literal">NULL</code> values.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.create_index("pop").\
field("demographics.Population", "INTEGER", False).execute()</code></strong>
Query OK (0.04 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678347584"></a>Add a Unique Index</h5>

</div>

</div>

</div>
<p>
          To create a unique index, pass to the
          <code class="literal">create_index()</code> method an index name and the
          <code class="literal">mysqlx.IndexType.UNIQUE</code> type. Country
          <code class="literal">"Name"</code> is another common field in the
          countryinfo collection to index. In the following example,
          <code class="literal">"Text(40)"</code> represents the number of
          characters to index and <code class="literal">True</code> indicates that
          the field cannot contain any <code class="literal">NULL</code> values.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.create_index("name", mysqlx.IndexType.UNIQUE).\
field("Name", "TEXT(40)", True).execute()</code></strong>
Query OK (0.04 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678340272"></a>Drop an Index</h5>

</div>

</div>

</div>
<p>
          To drop an index, pass to the <code class="literal">drop_index()</code>
          method the name of the index to drop. For example, you can
          drop the <span class="quote">“<span class="quote">pop</span>”</span> index as follows:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.drop_index("pop").execute()</code></strong>
Query OK (0.58 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678336304"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See
              <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-index-management-functions.html" target="_top">Collection Index Management Functions</a>
              for the full syntax definition.

              
</p></li></ul>
</div>

</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-python-relational-tables"></a>19.4.5 Relational Tables</h3>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-table-insert">19.4.5.1 Insert Records into Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-table-select">19.4.5.2 Select Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-table-update">19.4.5.3 Update Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-python-table-delete">19.4.5.4 Delete Tables</a></span></dt></dl>
</div>
<p>
      You can use MySQL Shell to manipulate not just JSON documents,
      but also relational tables.
    </p><p>
      In MySQL, each relational table is associated with a particular
      storage engine. The examples in this section use
      <a class="link" href="innodb-storage-engine.html" title="Chapter 14 The InnoDB Storage Engine"><code class="literal">InnoDB</code></a> tables in the
      <code class="literal">world_x</code> database.
</p>
<h4><a name="idm139684678328208"></a>Confirm the Schema</h4>
<p>
      To show the value that is assigned to the schema variable, type
      <code class="literal">db</code>.
    </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db</code></strong>
</pre><p>
      If the schema value is not the <code class="literal">Schema:world_x</code>
      database, then set the <code class="literal">db</code> variable as follows:
    </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>\use world_x</code></strong>
</pre>
<h4><a name="idm139684678321760"></a>Show All Tables</h4>
<p>
      To display all relational tables in the <code class="literal">world_x</code>
      database, use the <code class="literal">get_tables()</code> method on the
      schema object.
    </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.get_tables()</code></strong>
{
    "city": &lt;Table:city&gt;,
    "country": &lt;Table:country&gt;,
    "countrylanguage": &lt;Table:countrylanguage&gt;
}
</pre>
<h4><a name="idm139684678317568"></a>Basic Table Operations</h4>
<p>
      Basic operations scoped by tables include:
</p>
<div class="informaltable">
<table summary="CRUD operations to use interactively on tables within MySQL Shell"><col width="32%"><col width="68%"><thead><tr>
          <th scope="col">Operation form</th>
          <th scope="col">Description</th>
        </tr></thead><tbody><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.insert()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-python-table-insert" title="19.4.5.1 Insert Records into Tables">insert()</a>
            method inserts one or more records into the named table.</td>
        </tr><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.select()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-python-table-select" title="19.4.5.2 Select Tables">select()</a>
            method returns some or all records in the named table.</td>
        </tr><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.update()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-python-table-update" title="19.4.5.3 Update Tables">update()</a>
            method updates records in the named table.</td>
        </tr><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.delete()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-python-table-delete" title="19.4.5.4 Delete Tables">delete()</a>
            method deletes one or more records from the named table.</td>
</tr></tbody></table>
</div>
<h4><a name="idm139684678293440"></a>Related Information</h4>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          See
          <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-relational-tables.html" target="_top">Working with Relational Tables</a>
          for a general overview.
        </p></li><li class="listitem"><p>
          <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/mysql-x-crud-ebnf-definitions.html" target="_top">CRUD EBNF Definitions</a> provides a
          complete list of operations.
        </p></li><li class="listitem"><p>
          See <a class="xref" href="document-store.html#mysql-shell-tutorial-python-download" title="19.4.2 Import Database Sample">Section 19.4.2, “Import Database Sample”</a> for
          instructions on setting up the <code class="literal">world_x</code>
          database sample.
</p></li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-table-insert"></a>19.4.5.1 Insert Records into Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">insert()</code> method with the
        <code class="literal">values()</code> method to insert records into an
        existing relational table. The <code class="literal">insert()</code>
        method accepts individual columns or all columns in the table.
        Use one or more <code class="literal">values()</code> methods to specify
        the values to be inserted.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678282128"></a>Insert a Complete Record</h5>
</div>
</div>
</div>
<p>
          To insert a complete record, pass to the
          <code class="literal">insert()</code> method all columns in the table.
          Then pass to the <code class="literal">values()</code> method one value
          for each column. For example, to add a new record to the city
          table in the <code class="literal">world_x</code> database, insert the
          following record and press <span class="keycap"><strong>Enter</strong></span> twice.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.insert("ID", "Name", "CountryCode", "District", "Info").\
values(None, "Olympia", "USA", "Washington", '{"Population": 5000}')</code></strong>
Query OK, 1 item affected (0.01 sec)
</pre><p>
          The city table has five columns: ID, Name, CountryCode,
          District, and Info. Each value must match the data type of the
          column it represents.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678275664"></a>Insert a Partial Record</h5>

</div>

</div>

</div>
<p>
          The following example inserts values into the ID, Name, and
          CountryCode columns of the city table.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.insert("ID", "Name", "CountryCode").\
values(None, "Little Falls", "USA").values(None, "Happy Valley", "USA")</code></strong>
Query OK, 2 item affected (0.03 sec)
</pre><p>
          When you specify columns using the <code class="literal">insert()</code>
          method, the number of values must match the number of columns.
          In the previous example, you must supply three values to match
          the three columns specified.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678271536"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableinsertfunction" target="_top">TableInsertFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-table-select"></a>19.4.5.2 Select Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">select()</code> method to query for
        and return records from a table in a database. The
        X DevAPI provides additional methods to use with the
        <code class="literal">select()</code> method to filter and sort the
        returned records.
      </p><p>
        MySQL provides the following operators to specify search
        conditions: <code class="literal">OR</code> (<code class="literal">||</code>),
        <code class="literal">AND</code> (<code class="literal">&amp;&amp;</code>),
        <code class="literal">XOR</code>, <code class="literal">IS</code>,
        <code class="literal">NOT</code>, <code class="literal">BETWEEN</code>,
        <code class="literal">IN</code>, <code class="literal">LIKE</code>,
        <code class="literal">!=</code>, <code class="literal">&lt;&gt;</code>,
        <code class="literal">&gt;</code>, <code class="literal">&gt;=</code>,
        <code class="literal">&lt;</code>, <code class="literal">&lt;=</code>,
        <code class="literal">&amp;</code>, <code class="literal">|</code>,
        <code class="literal">&lt;&lt;</code>, <code class="literal">&gt;&gt;</code>,
        <code class="literal">+</code>, <code class="literal">-</code>,
        <code class="literal">*</code>, <code class="literal">/</code>,
        <code class="literal">~</code>, and <code class="literal">%</code>.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678246944"></a>Select All Records</h5>
</div>
</div>
</div>
<p>
          To issue a query that returns all records from an existing
          table, use the <code class="literal">select()</code> method without
          specifying search conditions. The following example selects
          all records from the city table in the
          <code class="literal">world_x</code> database.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
            Limit the use of the empty <code class="literal">select()</code>
            method to interactive statements. Always use explicit
            column-name selections in your application code.
</p>
</div>
<pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select()</code></strong>
+------+------------+-------------+------------+-------------------------+
| ID   | Name       | CountryCode | District   | Info                    |
+------+------------+-------------+------------+-------------------------+
|    1 | Kabul      | AFG         | Kabol      |{"Population": 1780000}  |
|    2 | Qandahar   | AFG         | Qandahar   |{"Population": 237500}   |
|    3 | Herat      | AFG         | Herat      |{"Population": 186800}   |
...    ...          ...           ...          ...
| 4079 | Rafah      | PSE         | Rafah      |{"Population": 92020}    |
+------+------- ----+-------------+------------+-------------------------+
4082 rows in set (0.01 sec)
</pre><p>
          An empty set (no matching records) returns the following
          information:
        </p><pre class="screen">
Empty set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678239200"></a>Filter Searches</h5>

</div>

</div>

</div>
<p>
          To issue a query that returns a set of table columns, use the
          <code class="literal">select()</code> method and specify the columns to
          return between square brackets. This query returns the Name
          and CountryCode columns from the city table.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"])</code></strong>
+-------------------+-------------+
| Name              | CountryCode |
+-------------------+-------------+
| Kabul             | AFG         |
| Qandahar          | AFG         |
| Herat             | AFG         |
| Mazar-e-Sharif    | AFG         |
| Amsterdam         | NLD         |
...                 ...
| Rafah             | PSE         |
| Olympia           | USA         |
| Little Falls      | USA         |
| Happy Valley      | USA         |
+-------------------+-------------+
4082 rows in set (0.00 sec)
</pre><p>
          To issue a query that returns rows matching specific search
          conditions, use the <code class="literal">where()</code> method to
          include those conditions. For example, the following example
          returns the names and country codes of the cities that start
          with the letter Z.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).where("Name like 'Z%'")</code></strong>
+-------------------+-------------+
| Name              | CountryCode |
+-------------------+-------------+
| Zaanstad          | NLD         |
| Zoetermeer        | NLD         |
| Zwolle            | NLD         |
| Zenica            | BIH         |
| Zagazig           | EGY         |
| Zaragoza          | ESP         |
| Zamboanga         | PHL         |
| Zahedan           | IRN         |
| Zanjan            | IRN         |
| Zabol             | IRN         |
| Zama              | JPN         |
| Zhezqazghan       | KAZ         |
| Zhengzhou         | CHN         |
...                 ...
| Zeleznogorsk      | RUS         |
+-------------------+-------------+
59 rows in set (0.00 sec)
</pre><p>
          You can separate a value from the search condition by using
          the <code class="literal">bind()</code> method. For example, instead of
          using "Name = 'Z%' " as the condition, substitute a named
          placeholder consisting of a colon followed by a name that
          begins with a letter, such as <span class="emphasis"><em>name</em></span>. Then
          include the placeholder and value in the
          <code class="literal">bind()</code> method as follows:
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).\
              where("Name like :name").bind("name", "Z%")</code></strong>
</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Tip
</div>
<p>
            Within a program, binding enables you to specify
            placeholders in your expressions, which are filled in with
            values before execution and can benefit from automatic
            escaping, as appropriate.
          </p><p>
            Always use binding to sanitize input. Avoid introducing
            values in queries using string concatenation, which can
            produce invalid input and, in some cases, can cause security
            issues.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678225808"></a>Project Results</h5>

</div>

</div>

</div>
<p>
          To issue a query using the <a class="link" href="functions.html#operator_and"><code class="literal">AND</code></a>
          operator, add the operator between search conditions in the
          <code class="literal">where()</code> method.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).\
               where("Name like 'Z%' and CountryCode = 'CHN'")</code></strong>
+----------------+-------------+
| Name           | CountryCode |
+----------------+-------------+
| Zhengzhou      | CHN         |
| Zibo           | CHN         |
| Zhangjiakou    | CHN         |
| Zhuzhou        | CHN         |
| Zhangjiang     | CHN         |
| Zigong         | CHN         |
| Zaozhuang      | CHN         |
...              ...
| Zhangjiagang   | CHN         |
+----------------+-------------+
22 rows in set (0.01 sec)
</pre><p>
          To specify multiple conditional operators, you can enclose the
          search conditions in parenthesis to change the operator
          precedence. The following example demonstrates the placement
          of <a class="link" href="functions.html#operator_and"><code class="literal">AND</code></a> and
          <a class="link" href="functions.html#operator_or"><code class="literal">OR</code></a> operators.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).\
where("Name like 'Z%' and (CountryCode = 'CHN' or CountryCode = 'RUS')")</code></strong>
+-------------------+-------------+
| Name              | CountryCode |
+-------------------+-------------+
| Zhengzhou         | CHN         |
| Zibo              | CHN         |
| Zhangjiakou       | CHN         |
| Zhuzhou           | CHN         |
...                 ...
| Zeleznogorsk      | RUS         |
+-------------------+-------------+
29 rows in set (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678215776"></a>Limit, Order, and Offset Results</h5>

</div>

</div>

</div>
<p>
          You can apply the <code class="literal">limit()</code>,
          <code class="literal">order_by()</code>, and <code class="literal">offset()</code>
          methods to manage the number and order of records returned by
          the <code class="literal">select()</code> method.
        </p><p>
          To specify the number of records included in a result set,
          append the <code class="literal">limit()</code> method with a value to
          the <code class="literal">select()</code> method. For example, the
          following query returns the first five records in the country
          table.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.country.select(["Code", "Name"]).limit(5)</code></strong>
+------+-------------+
| Code | Name        |
+------+-------------+
| ABW  | Aruba       |
| AFG  | Afghanistan |
| AGO  | Angola      |
| AIA  | Anguilla    |
| ALB  | Albania     |
+------+-------------+
5 rows in set (0.00 sec)
</pre><p>
          To specify an order for the results, append the
          <code class="literal">order_by()</code> method to the
          <code class="literal">select()</code> method. Pass to the
          <code class="literal">order_by()</code> method a list of one or more
          columns to sort by and, optionally, the descending
          (<code class="literal">desc</code>) or ascending
          (<code class="literal">asc</code>) attribute as appropriate. Ascending
          order is the default order type.
        </p><p>
          For example, the following query sorts all records by the Name
          column and then returns the first three records in descending
          order .
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.country.select(["Code", "Name"]).order_by(["Name desc"]).limit(3)</code></strong>
+------+------------+
| Code | Name       |
+------+------------+
| ZWE  | Zimbabwe   |
| ZMB  | Zambia     |
| YUG  | Yugoslavia |
+------+------------+
3 rows in set (0.00 sec)
</pre><p>
          By default, the <code class="literal">limit()</code> method starts from
          the first record in the table. You can use the
          <code class="literal">offset()</code> method to change the starting
          record. For example, to ignore the first record and return the
          next three records matching the condition, pass to the
          <code class="literal">offset()</code> method a value of 1.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.country.select(["Code", "Name"]).order_by(["Name desc"]).limit(3).offset(1)</code></strong>
+------+------------+
| Code | Name       |
+------+------------+
| ZMB  | Zambia     |
| YUG  | Yugoslavia |
| YEM  | Yemen      |
+------+------------+
3 rows in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678196960"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              The <a class="link" href="functions.html" title="Chapter 12 Functions and Operators">MySQL Reference
              Manual</a> provides detailed documentation on functions
              and operators.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableselectfunction" target="_top">TableSelectFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-table-update"></a>19.4.5.3 Update Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">update()</code> method to modify one
        or more records in a table. The <code class="literal">update()</code>
        method works by filtering a query to include only the records to
        be updated and then applying the operations you specify to those
        records.
      </p><p>
        To replace a city name in the city table, pass to the
        <code class="literal">set()</code> method the new city name. Then, pass to
        the <code class="literal">where()</code> method the city name to locate
        and replace. The following example replaces the city Peking with
        Beijing.
      </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.update().set("Name", "Beijing").where("Name = 'Peking'")</code></strong>
Query OK, 1 item affected (0.04 sec)
</pre><p>
        Use the <code class="literal">select()</code> method to verify the change.
      </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).where("Name = 'Beijing'")</code></strong>
+------+-----------+-------------+----------+-----------------------------+
| ID   | Name      | CountryCode | District | Info                        |
+------+-----------+-------------+----------+-----------------------------+
| 1891 | Beijing   | CHN         | Peking   | {"Population": 7472000}     |
+------+-----------+-------------+----------+-----------------------------+
1 row in set (0.00 sec)
</pre>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678182480"></a>Related Information</h5>
</div>
</div>
</div>

<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableupdatefunction" target="_top">TableUpdateFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-python-table-delete"></a>19.4.5.4 Delete Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">delete()</code> method to remove
        some or all records from a table in a database. The
        X DevAPI provides additional methods to use with the
        <code class="literal">delete()</code> method to filter and order the
        records to be deleted.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684678176224"></a>Delete Records Using Conditions</h5>
</div>
</div>
</div>
<p>
          The example that follows passes search conditions to the
          <code class="literal">delete()</code> method. All records matching the
          condition will be deleted from the city table. In this
          example, one record matches the condition.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.delete().where("Name = 'Olympia'")</code></strong>
Query OK, 1 item affected (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678172672"></a>Delete the First Record</h5>

</div>

</div>

</div>
<p>
          To delete the first record in the city table, use the
          <code class="literal">limit()</code> method with a value of 1.
        </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.delete().limit(1)</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678169216"></a>Delete All Records in a Table</h5>

</div>

</div>

</div>
<p>
          You can delete all records in a table. To do so, use the
          <code class="literal">delete()</code> method without specifying a search
          condition.
</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Caution
</div>
<p>
            Use care when you delete records without specifying a search
            condition. This action will delete all records from the
            table.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684678166192"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tabledeletefunction" target="_top">TableDeleteFunction</a> for
              the full syntax definition.
            </p></li><li class="listitem"><p>
              See <a class="xref" href="document-store.html#mysql-shell-tutorial-python-download" title="19.4.2 Import Database Sample">Section 19.4.2, “Import Database Sample”</a>
              for instructions to recreate the
              <code class="literal">world_x</code> database.
</p></li></ul>
</div>

</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-python-documents-in-tables"></a>19.4.6 Documents in Tables</h3>

</div>

</div>

</div>
<p>
      In MySQL, a table may contain traditional relational data, JSON
      values, or both. You can combine traditional data with JSON
      documents by storing the documents in columns having a native
      <a class="link" href="data-types.html#json" title="11.6 The JSON Data Type"><code class="literal">JSON</code></a> data type.
    </p><p>
      Examples in this section use the city table in the
      <code class="literal">world_x</code> database.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h4 class="title"><a name="idm139684678156512"></a>city Table Description</h4>
</div>
</div>
</div>
<p>
        The city table has five columns (or fields).
      </p><pre class="screen">
+---------------+------------+-------+-------+---------+------------------+
| Field         | Type       | Null  | Key   | Default | Extra            |
+---------------+------------+-------+-------+---------+------------------+
| ID            | int(11)    | NO    | PRI   | null    | auto_increment   |
| Name          | char(35)   | NO    |       |         |                  |
| CountryCode   | char(3)    | NO    |       |         |                  |
| District      | char(20)   | NO    |       |         |                  |
| Info          | json       | YES   |       | null    |                  |
+---------------+------------+-------+-------+---------+------------------+
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678153888"></a>Insert a Record</h4>

</div>

</div>

</div>
<p>
        To insert a document into the column of a table, pass to the
        <code class="literal">values()</code> method a well-formed JSON document
        in the correct order. In the following example, a document is
        passed as the final value to be inserted into the Info column.
      </p><pre class="programlisting"> mysql-py&gt; <strong class="userinput"><code>db.city.insert().\
values(None, "San Francisco", "USA", "California", '{"Population":830000}')</code></strong>
Query OK, 1 item affected (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678150224"></a>Select a Record</h4>

</div>

</div>

</div>
<p>
        You can issue a query with a search condition that evaluates
        document values in the expression.
      </p><pre class="programlisting">
mysql-py&gt; <strong class="userinput"><code>db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).\
  where("CountryCode = :country and Info-&gt;'$.Population' &gt; 1000000").\
  bind('country', 'USA')</code></strong>
+------+----------------+-------------+----------------+-----------------------------+
| ID   | Name           | CountryCode | District       | Info                        |
+------+----------------+-------------+----------------+-----------------------------+
| 3793 | New York       | USA         | New York       | {"Population": 8008278}     |
| 3794 | Los Angeles    | USA         | California     | {"Population": 3694820}     |
| 3795 | Chicago        | USA         | Illinois       | {"Population": 2896016}     |
| 3796 | Houston        | USA         | Texas          | {"Population": 1953631}     |
| 3797 | Philadelphia   | USA         | Pennsylvania   | {"Population": 1517550}     |
| 3798 | Phoenix        | USA         | Arizona        | {"Population": 1321045}     |
| 3799 | San Diego      | USA         | California     | {"Population": 1223400}     |
| 3800 | Dallas         | USA         | Texas          | {"Population": 1188580}     |
| 3801 | San Antonio    | USA         | Texas          | {"Population": 1144646}     |
+------+----------------+-------------+----------------+-----------------------------+
9 rows in set (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678144992"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            See
            <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-relational-tables-and-documents.html" target="_top">Working with Relational Tables and Documents</a>
            for a general overview.
          </p></li><li class="listitem"><p>
            See <a class="xref" href="data-types.html#json" title="11.6 The JSON Data Type">Section 11.6, “The JSON Data Type”</a> for a detailed description of the
            data type.
</p></li></ul>
</div>

</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="mysql-shell-tutorial-javascript"></a>19.5 Quick-Start Guide: MySQL Shell for JavaScript</h2>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-introduction">19.5.1 Introduction</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-download">19.5.2 Import Database Sample</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-shell">19.5.3 MySQL Shell</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-collections">19.5.4 Documents and Collections</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-relational-tables">19.5.5 Relational Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-in-tables">19.5.6 Documents in Tables</a></span></dt></dl>
</div>
<p>
    This quick-start guide provides instructions to begin prototyping
    database applications interactively with MySQL Shell. The guide
    includes the following topics:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Introduction to MySQL functionality, MySQL Shell, and the
        <code class="literal">world_x</code> database sample.
      </p></li><li class="listitem"><p>
        Operations to manage collections and documents.
      </p></li><li class="listitem"><p>
        Operations to manage relational tables.
      </p></li><li class="listitem"><p>
        Operations that apply to documents within tables.
</p></li></ul>
</div>
<h3><a name="idm139684678134144"></a>Available Quick-Start Guides</h3>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        <a class="link" href="document-store.html#mysql-shell-tutorial-python" title="19.4 Quick-Start Guide: MySQL Shell for Python">MySQL Shell for
        Python</a>
      </p></li><li class="listitem"><p>
        <a class="link" href="document-store.html#mysql-shell-visual-studio" title="19.6 Quick-Start Guide: MySQL for Visual Studio">MySQL for Visual
        Studio</a>
</p></li></ul>
</div>
<h3><a name="idm139684678129808"></a>Related Information</h3>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/" target="_top">MySQL Shell 8.0 (part of MySQL 8.0)</a> provides more in-depth information
        about MySQL Shell.
      </p></li><li class="listitem"><p>
        <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/" target="_top">X DevAPI User Guide</a> provides more examples of
        using X DevAPI.
</p></li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-javascript-introduction"></a>19.5.1 Introduction</h3>

</div>

</div>

</div>
<p>
      The MySQL Shell for JavaScript quick start provides a short but
      comprehensive introduction to the database functionality including
      the new X DevAPI, which offers a modern, integrative way to
      work with relational and document data, without requiring SQL
      knowledge from application developers.
    </p><p>
      In MySQL, tables are the native data storage container type and
      collections are stored internally using tables.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h4 class="title"><a name="idm139684678123056"></a>JSON Documents and Collections</h4>
</div>
</div>
</div>
<p>
        A JSON
        <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-documents" title="Documents">document</a>
        is a data structure composed of field/value pairs stored within
        a
        <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-collections" title="Collections">collection</a>.
        The values of fields often contain other documents, arrays, and
        lists of documents.
      </p><pre class="programlisting">
{
    "GNP": .6,
    "IndepYear": 1967,
    "Name": "Sealand",
    "_id": "SEA",
    "demographics": {
        "LifeExpectancy": 79,
        "Population": 27
    },
    "geography": {
        "Continent": "Europe",
        "Region": "British Islands",
        "SurfaceArea": 193
    },
    "government": {
        "GovernmentForm": "Monarchy",
        "HeadOfState": "Michael Bates"
    }
}
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678118480"></a>Relational Tables</h4>

</div>

</div>

</div>
<p>
        A
        <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-relational-tables" title="19.5.5 Relational Tables">table</a>
        in MySQL enables you to store data organized in rows and
        columns. The structure of a table is defined by one or more
        columns with user-defined names and data types. Every row stored
        in the table has the same structure.
      </p><pre class="programlisting">
+------+------------------+-------------+-----------------+------------------------+
| ID   | Name             | CountryCode | District        | Info                   |
+------+------------------+-------------+-----------------+------------------------+
|    1 | Kabul            | AFG         | Kabol           |{"Population": 1780000} |
|    2 | Qandahar         | AFG         | Qandahar        |{"Population": 237500}  |
|    3 | Herat            | AFG         | Herat           |{"Population": 186800}  |
|    4 | Mazar-e-Sharif   | AFG         | Balkh           |{"Population": 127800}  |
|    5 | Amsterdam        | NLD         | Noord-Holland   |{"Population": 731200}  |
|    6 | Rotterdam        | NLD         | Zuid-Holland    |{"Population": 593321}  |
+------+------------------+-------------+-----------------+------------------------+
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678114432"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/" target="_top">MySQL Shell 8.0 (part of MySQL 8.0)</a> provides a general overview.
          </p></li><li class="listitem"><p>
            See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/" target="_top">X DevAPI User Guide</a> for development
            reference documentation.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-javascript-download"></a>19.5.2 Import Database Sample</h3>

</div>

</div>

</div>
<p>
      The <code class="literal">world_x</code> database sample contains one JSON
      collection and a set of three relational tables:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Collection
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
              countryinfo: Information about countries in the world.
</p></li></ul>
</div>
</li><li class="listitem"><p>
          Tables
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
              country: Minimal information about countries of the world.
            </p></li><li class="listitem"><p>
              city: Information about some of the cities in those
              countries.
            </p></li><li class="listitem"><p>
              countrylanguage: Languages spoken in each country.
</p></li></ul>
</div>
</li></ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678101248"></a>Requirements</h4>

</div>

</div>

</div>
<p>
        You must install MySQL Shell with the X Protocol
        enabled. For instructions, see
        <a class="xref" href="document-store.html#document-store-setting-up" title="19.3 Setting Up MySQL as a Document Store">Section 19.3, “Setting Up MySQL as a Document Store”</a>.
      </p><p>
        Start the server before you load the <code class="literal">world_x</code>
        database for this guide.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678098048"></a>Download world_x Database</h4>

</div>

</div>

</div>
<p>
        To prepare the <code class="literal">world_x</code> database sample,
        follow these steps:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
            Download
            <a class="ulink" href="http://downloads.mysql.com/docs/world_x-db.zip" target="_top">world_x-db.zip</a>.
          </p></li><li class="listitem"><p>
            Extract the installation archive to a temporary location
            such as <code class="filename">/tmp/</code>. Unpacking the archive
            results in a single file named
            <code class="filename">world_x.sql</code>.
          </p></li><li class="listitem"><p>
            Create the schema with the following command:
          </p><pre class="programlisting">
<strong class="userinput"><code>mysqlsh -u root --sql &lt; /tmp/world_x-db/world_x.sql</code></strong>
Enter password: <strong class="userinput"><code>****</code></strong>
</pre><p>
            Enter your password when prompted. A non-root account can be
            used as long as the account has privileges to create new
            databases.
          </p><p>
            Replace <code class="filename">/tmp/</code> with the path to the
            <code class="filename">world_x.sql</code> file on your system.
</p></li></ol>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678085712"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-sessions.html" target="_top">MySQL Shell Sessions</a> explains session
            types.
          </p></li><li class="listitem"><p>
            See <a class="xref" href="installing.html" title="Chapter 2 Installing and Upgrading MySQL">Chapter 2, <i>Installing and Upgrading MySQL</i></a> for general installation
            assistance.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-javascript-shell"></a>19.5.3 MySQL Shell</h3>

</div>

</div>

</div>
<p>
      MySQL Shell is a unified scripting interface to MySQL Server. It
      supports scripting in JavaScript and Python. JavaScript is the
      default processing mode. In most cases, you need an account to
      connect to the local MySQL server instance.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h4 class="title"><a name="mysql-shell-tutorial-javascript-shell-start"></a>Start MySQL Shell</h4>
</div>
</div>
</div>
<p>
        After you have installed and started MySQL server, connect
        MySQL Shell to the server instance. By default, MySQL Shell
        connects using the X Protocol.
      </p><p>
        On the same system where the server instance is running, open a
        terminal window and start MySQL Shell with the following
        command:
      </p><pre class="programlisting">
<strong class="userinput"><code>mysqlsh <em class="replaceable"><code>name</code></em>@localhost/world_x</code></strong>
Creating a Session to 'root@localhost/world_x'
Enter password:<strong class="userinput"><code> ****</code></strong>
</pre><p>
        You may need to specify the path as appropriate.
      </p><p>
        In addition:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <em class="replaceable"><code>name</code></em> represents the user name of
            your MySQL account.
          </p></li><li class="listitem"><p>
            MySQL Shell prompts you for your password.
          </p></li><li class="listitem"><p>
            The default schema for this session is the
            <code class="literal">world_x</code> database. For instructions on
            setting up the <code class="literal">world_x</code> database sample,
            see
            <a class="xref" href="document-store.html#mysql-shell-tutorial-javascript-download" title="19.5.2 Import Database Sample">Section 19.5.2, “Import Database Sample”</a>.
</p></li></ul>
</div>
<p>
        The <code class="literal">mysql-js&gt;</code> prompt indicates that the
        active language for this session is JavaScript.
      </p><pre class="programlisting">
mysql-js&gt;
</pre><p>
        When you run <span class="command"><strong>mysqlsh</strong></span> without the host
        argument, MySQL Shell attempts to connect to the server
        instance running on the localhost interface on port 33060. To
        specify a different host or port number, as well as other
        options, see the option descriptions at
        <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysqlsh.html" target="_top"><span class="command"><strong>mysqlsh</strong></span> — The MySQL Shell</a>.
      </p><p>
        MySQL Shell supports input-line editing as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            <span class="keycap"><strong>left-arrow</strong></span> and <span class="keycap"><strong>right-arrow</strong></span>
            keys move horizontally within the current input line.
          </p></li><li class="listitem"><p>
            <span class="keycap"><strong>up-arrow</strong></span> and <span class="keycap"><strong>down-arrow</strong></span>
            keys move up and down through the set of previously entered
            lines.
          </p></li><li class="listitem"><p>
            <span class="keycap"><strong>Backspace</strong></span> deletes the character before the
            cursor and typing new characters enters them at the cursor
            position.
          </p></li><li class="listitem"><p>
            <span class="keycap"><strong>Enter</strong></span> enters the current input line.
</p></li></ul>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="mysql-shell-tutorial-javascript-shell-help"></a>Get Help for MySQL Shell</h4>

</div>

</div>

</div>
<p>
        Type <span class="command"><strong>mysqlsh --help</strong></span> at the prompt of your
        command interpreter for a list of command-line options.
      </p><pre class="programlisting">
<strong class="userinput"><code>mysqlsh --help</code></strong>
</pre><p>
        Type <code class="literal">\help</code> at the MySQL Shell prompt for a
        list of available commands and their descriptions.
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>\help</code></strong>
</pre><p>
        Type <code class="literal">\help</code> followed by a command name for
        detailed help about an individual MySQL Shell command. For
        example, to view help on the <code class="literal">\connect</code>
        command, type:
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>\help \connect</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="mysql-shell-tutorial-javascript-shell-quit"></a>Quit MySQL Shell</h4>

</div>

</div>

</div>
<p>
        To quit MySQL Shell, type the following command:
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>\quit</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684678041520"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            See <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-interactive-code-execution.html" target="_top">Interactive Code Execution</a>
            for an explanation of how interactive code execution works
            in MySQL Shell.
          </p></li><li class="listitem"><p>
            See <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-getting-started.html" target="_top">Getting Started with MySQL Shell</a> to learn
            about session and connection alternatives.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-javascript-documents-collections"></a>19.5.4 Documents and Collections</h3>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-collections-operations">19.5.4.1 Create, List, and Drop Collections</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-collections-add">19.5.4.2 Add Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-find">19.5.4.3 Find Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-modify">19.5.4.4 Modify Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-documents-remove">19.5.4.5 Remove Documents</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-indexes-create">19.5.4.6 Create and Drop Indexes</a></span></dt></dl>
</div>
<p>
      In MySQL, collections contain JSON documents that you can add,
      find, update, and remove. Collections are containers within a
      schema that you create, list, and drop.
    </p><p>
      The examples in this section use the countryinfo collection in the
      <code class="literal">world_x</code> database. For instructions on setting
      up the <code class="literal">world_x</code> database sample, see
      <a class="xref" href="document-store.html#mysql-shell-tutorial-javascript-download" title="19.5.2 Import Database Sample">Section 19.5.2, “Import Database Sample”</a>.
</p>
<h4><a name="mysql-shell-tutorial-javascript-documents"></a>Documents</h4>
<p>
      In MySQL, documents are represented as JSON objects. Internally,
      they are stored in an efficient binary format that enables fast
      lookups and updates.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Simple document format for JavaScript:
        </p><pre class="screen">
{field1: "value", field2 : 10, "field 3": null}
</pre></li></ul>
</div>
<p>
      An array of documents consists of a set of documents separated by
      commas and enclosed within <code class="literal">[</code> and
      <code class="literal">]</code> characters.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Simple array of documents for JavaScript:
        </p><pre class="screen">
[{Name: "Aruba", _id: "ABW"}, {Name: "Angola", _id: "AGO"}]
</pre></li></ul>
</div>
<p>
      MySQL supports the following JavaScript value types in JSON
      documents:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          numbers (integer and floating point)
        </p></li><li class="listitem"><p>
          strings
        </p></li><li class="listitem"><p>
          boolean (false and true)
        </p></li><li class="listitem"><p>
          null
        </p></li><li class="listitem"><p>
          arrays of more JSON values
        </p></li><li class="listitem"><p>
          nested (or embedded) objects of more JSON values
</p></li></ul>
</div>
<h4><a name="mysql-shell-tutorial-javascript-collections"></a>Collections</h4>
<p>
      Collections are containers for documents that share a purpose and
      possibly share one or more indexes. Each collection has a unique
      name and exists within a single schema.
    </p><p>
      The term schema is equivalent to a database, which means a group
      of database objects (as opposed to relational schema used to
      enforce structure and constraints over data). A schema does not
      enforce conformity on the documents in a collection.
    </p><p>
      In this quick-start guide:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          Basic objects include:
</p>
<div class="informaltable">
<table summary="Objects to use interactively within MySQL Shell"><col width="40%"><col width="60%"><thead><tr>
              <th scope="col">Object form</th>
              <th scope="col">Description</th>
            </tr></thead><tbody><tr>
              <td scope="row"><code class="literal">db</code></td>
              <td><code class="literal">db</code> is a global variable assigned to the current
                active schema that you specified on the command line.
                You can type <code class="literal">db</code> in MySQL Shell to
                print a description of the object, which in this case
                will be the name of the schema it represents.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.getCollections()</code></td>
              <td><a class="link" href="document-store.html#mysql-shell-tutorial-javascript-collections-get" title="List Collections">db.getCollections()</a>
                holds a list of collections in the schema. Use the list
                to get references to collection objects, iterate over
                them, and so on.</td>
</tr></tbody></table>
</div>
</li><li class="listitem"><p>
          Basic operations scoped by collections include:
</p>
<div class="informaltable">
<table summary="CRUD operations to use interactively on documents within MySQL Shell"><col width="40%"><col width="60%"><thead><tr>
              <th scope="col">Operation form</th>
              <th scope="col">Description</th>
            </tr></thead><tbody><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.add()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-collections-add" title="19.5.4.2 Add Documents">add()</a>
                method inserts one document or a list of documents into
                the named collection.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.find()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-documents-find" title="19.5.4.3 Find Documents">find()</a>
                method returns some or all documents in the named
                collection.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.modify()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-documents-modify" title="19.5.4.4 Modify Documents">modify()</a>
                method updates documents in the named collection.</td>
            </tr><tr>
              <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.remove()</code></td>
              <td>The
                <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-documents-remove" title="19.5.4.5 Remove Documents">remove()</a>
                method deletes one document or a list of documents from
                the named collection.</td>
</tr></tbody></table>
</div>
</li></ul>
</div>
<h4><a name="idm139684677977136"></a>Related Information</h4>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-collections.html" target="_top">Working with Collections</a>
          for a general overview.
        </p></li><li class="listitem"><p>
          <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/mysql-x-crud-ebnf-definitions.html" target="_top">CRUD EBNF Definitions</a> provides a
          complete list of operations.
</p></li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-collections-operations"></a>19.5.4.1 Create, List, and Drop Collections</h4>

</div>

</div>

</div>
<p>
        In MySQL Shell, you can create new collections, get a list of
        the existing collections in a schema, and remove an existing
        collection from a schema. Collection names are case-sensitive
        and each collection name must be unique.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677970912"></a>Confirm the Schema</h5>
</div>
</div>
</div>
<p>
          To show the value that is assigned to the schema variable,
          type <code class="literal">db</code>.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db</code></strong>
</pre><p>
          If the schema value is not <code class="literal">Schema:world_x</code>,
          then set the <code class="literal">db</code> variable as follows:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>\use world_x</code></strong>
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-javascript-collections-create"></a>Create a Collection</h5>

</div>

</div>

</div>
<p>
          To create a new collection in an existing schema, use the
          <code class="literal">createCollection()</code> method. The following
          example creates in the <code class="literal">world_x</code> database a
          collection called flags.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.createCollection("flags")</code></strong>
</pre><p>
          The method returns a collection object.
</p><pre class="screen">&lt;Collection:flags&gt;</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-javascript-collections-get"></a>List Collections</h5>

</div>

</div>

</div>
<p>
          To display all collections in the <code class="literal">world_x</code>
          database, use the <code class="literal">getCollections()</code> method
          on the schema object. Collections returned by the server
          appear between brackets.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.getCollections()</code></strong>
[
    &lt;Collection:countryinfo&gt;,
    &lt;Collection:flags&gt;
]
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-javascript-collections-drop"></a>Drop a Collection</h5>

</div>

</div>

</div>
<p>
          To drop an existing collection from a database, use the
          <code class="literal">dropCollection()</code> method on the session
          object. For example, to drop the flags collection from the
          <code class="literal">world_x</code> database, type:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>session.dropCollection("world_x", "flags")</code></strong>
Query OK (0.04 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677949008"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See
              <a class="ulink" href="http://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-connections-in-javascript-and-python.html" target="_top">Connections in JavaScript and Python</a>
              to learn more about the session object.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/collection-objects.html" target="_top">Collection Objects</a> for more
              examples.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-collections-add"></a>19.5.4.2 Add Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">add()</code> method to insert one
        document or a list documents into an existing collection using
        MySQL Shell. All examples in this section use the countryinfo
        collection.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677941856"></a>Confirm the Schema</h5>
</div>
</div>
</div>
<p>
          To show the value that is assigned to the schema variable,
          type <code class="literal">db</code>.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db</code></strong>
&lt;Schema:world_x&gt;
</pre><p>
          If the schema value is not <code class="literal">Schema:world_x</code>,
          then set the <code class="literal">db</code> variable as follows:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>\use world_x</code></strong>
Schema `world_x` accessible through db.
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677935248"></a>Add a Document</h5>

</div>

</div>

</div>
<p>
          Insert the following document into the countryinfo collection.
          Press <span class="keycap"><strong>Enter</strong></span> twice to insert the document.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.add(
 {
    GNP: .6,
    IndepYear: 1967,
    Name: "Sealand",
    _id: "SEA",
    demographics: {
        LifeExpectancy: 79,
        Population: 27
    },
    geography: {
        Continent: "Europe",
        Region: "British Islands",
        SurfaceArea: 193
    },
    government: {
        GovernmentForm: "Monarchy",
        HeadOfState: "Michael Bates"
    }
  }
)</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre><p>
          The method returns the status of the operation.
        </p><p>
          Each document requires an identifier field called
          <code class="literal">_id</code>. The value of the
          <code class="literal">_id</code> field must be unique among all
          documents in the same collection. If the document passed to
          the <code class="literal">add()</code> method does not contain the
          <code class="literal">_id</code> field, MySQL Shell automatically
          inserts a field into the document and sets the value to a
          generated universal unique identifier (UUID).
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677927440"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionaddfunction" target="_top">CollectionAddFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-documents-find"></a>19.5.4.3 Find Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">find()</code> method to query for
        and return documents from a collection in a database.
        MySQL Shell provides additional methods to use with the
        <code class="literal">find()</code> method to filter and sort the returned
        documents.
      </p><p>
        MySQL provides the following operators to specify search
        conditions: <code class="literal">OR</code> (<code class="literal">||</code>),
        <code class="literal">AND</code> (<code class="literal">&amp;&amp;</code>),
        <code class="literal">XOR</code>, <code class="literal">IS</code>,
        <code class="literal">NOT</code>, <code class="literal">BETWEEN</code>,
        <code class="literal">IN</code>, <code class="literal">LIKE</code>,
        <code class="literal">!=</code>, <code class="literal">&lt;&gt;</code>,
        <code class="literal">&gt;</code>, <code class="literal">&gt;=</code>,
        <code class="literal">&lt;</code>, <code class="literal">&lt;=</code>,
        <code class="literal">&amp;</code>, <code class="literal">|</code>,
        <code class="literal">&lt;&lt;</code>, <code class="literal">&gt;&gt;</code>,
        <code class="literal">+</code>, <code class="literal">-</code>,
        <code class="literal">*</code>, <code class="literal">/</code>,
        <code class="literal">~</code>, and <code class="literal">%</code>.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677902832"></a>Find All Documents in a Collection</h5>
</div>
</div>
</div>
<p>
          To return all documents in a collection, use the
          <code class="literal">find()</code> method without specifying search
          conditions. For example, the following operation returns all
          documents in the countryinfo collection.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find()</code></strong>
[
     {
          "GNP": 828,
          "IndepYear": null,
          "Name": "Aruba",
          "_id": "ABW",
          "demographics": {
              "LifeExpectancy": 78.4000015258789,
              "Population": 103000
          },
          "geography": {
              "Continent": "North America",
              "Region": "Caribbean",
              "SurfaceArea": 193
          },
          "government": {
              "GovernmentForm": "Nonmetropolitan Territory of The Netherlands",
              "HeadOfState": "Beatrix"
          }
          ...
      }
 ]
240 documents in set (0.00 sec)
</pre><p>
          The method produces results that contain operational
          information in addition to all documents in the collection.
        </p><p>
          An empty set (no matching documents) returns the following
          information:
        </p><pre class="screen">
Empty set (0.00 sec) 
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="mysql-shell-tutorial-javascript-documents-find-filter-searches"></a>Filter Searches</h5>

</div>

</div>

</div>
<p>
          You can include search conditions with the
          <code class="literal">find()</code> method. The syntax for expressions
          that form a search condition is the same as that of
          traditional <a class="link" href="functions.html" title="Chapter 12 Functions and Operators">MySQL</a>. You must
          enclose all expressions in quotes.
        </p><p>
          All examples in this section use the countryinfo collection in
          the <code class="literal">world_x</code> database. For the sake of
          brevity, some of the examples do not display output.
        </p><p>
          A simple search condition consists of the
          <code class="literal">_id</code> field and unique identifier of a
          document. The following example returns a single document
          matching the identifier string:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("_id = 'AUS'")</code></strong>
[
    {
        "GNP": 351182,
        "IndepYear": 1901,
        "Name": "Australia",
        "_id": "AUS",
        "demographics": {
            "LifeExpectancy": 79.80000305175781,
            "Population": 18886000
        },
        "geography": {
            "Continent": "Oceania",
            "Region": "Australia and New Zealand",
            "SurfaceArea": 7741220
        },
        "government": {
            "GovernmentForm": "Constitutional Monarchy, Federation",
            "HeadOfState": "Elisabeth II"
        }
    }
]
1 document in set (0.01 sec)
</pre><p>
          The following example searches for all countries that have a
          GNP higher than $500 billion. The countryinfo collection
          measures GNP in units of million.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("GNP &gt; 500000")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
10 documents in set (0.00 sec)
</pre><p>
          The Population field in the following query is embedded within
          the demographics object. To access the embedded field, use a
          period between demographics and Population to identify the
          relationship. Document and field names are case-sensitive.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("GNP &gt; 500000 and demographics.Population &lt; 100000000")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
6 documents in set (0.00 sec)
</pre><p>
          Arithmetic operators in the following expression are used to
          query for countries with a GNP per capita higher than $30000.
          Search conditions can include arithmetic operators and most
          MySQL functions.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
            Seven documents in the countryinfo collection have a
            population value of zero. Warning messages appear at the end
            of the output.
</p>
</div>
<pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("GNP*1000000/demographics.Population &gt; 30000")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
9 documents in set, 7 warnings (0.00 sec)
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
</pre><p>
          You can separate a value from the search condition by using
          the <code class="literal">bind()</code> method. For example, instead of
          specifying a hard-coded country name as the condition,
          substitute a named placeholder consisting of a colon followed
          by a name that begins with a letter, such as
          <span class="emphasis"><em>country</em></span>. Then include the placeholder and
          value in the <code class="literal">bind()</code> method as follows:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("Name = :country").bind("country", "Italy")</code></strong>
[
    {
        "GNP": 1161755,
        "IndepYear": 1861,
        "Name": "Italy",
        "_id": "ITA",
        "demographics": {
            "LifeExpectancy": 79,
            "Population": 57680000
        },
        "geography": {
            "Continent": "Europe",
            "Region": "Southern Europe",
            "SurfaceArea": 301316
        },
        "government": {
            "GovernmentForm": "Republic",
            "HeadOfState": "Carlo Azeglio Ciampi"
        }
    }
]
1 document in set (0.01 sec)
</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Tip
</div>
<p>
            Within a program, binding enables you to specify
            placeholders in your expressions, which are filled in with
            values before execution and can benefit from automatic
            escaping, as appropriate.
          </p><p>
            Always use binding to sanitize input. Avoid introducing
            values in queries using string concatenation, which can
            produce invalid input and, in some cases, can cause security
            issues.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677873536"></a>Project Results</h5>

</div>

</div>

</div>
<p>
          You can return specific fields of a document, instead of
          returning all the fields. The following example returns the
          GNP and Name fields of all documents in the countryinfo
          collection matching the search conditions.
        </p><p>
          Use the <code class="literal">fields()</code> method to pass the list of
          fields to return.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("GNP &gt; 5000000").fields(["GNP", "Name"])</code></strong>
[
    {
        "GNP": 8510700,
        "Name": "United States"
    }
]
1 document in set (0.00 sec)
 </pre><p>
          In addition, you can alter the returned
          documents—adding, renaming, nesting and even computing
          new field values—with an expression that describes the
          document to return. For example, alter the names of the fields
          with the following expression to return only two documents.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find().
fields(mysqlx.expr('{"Name": upper(Name), "GNPPerCapita": GNP*1000000/demographics.Population}')).
limit(2)</code></strong>
[
    {
        "GNPPerCapita": 8038.834951456311,
        "Name": "ARUBA"
    },
    {
        "GNPPerCapita": 263.0281690140845,
        "Name": "AFGHANISTAN"
    }
]
2 documents in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677866448"></a>Limit, Sort, and Skip Results</h5>

</div>

</div>

</div>
<p>
          You can apply the <code class="literal">limit()</code>,
          <code class="literal">sort()</code>, and <code class="literal">skip()</code>
          methods to manage the number and order of documents returned
          by the <code class="literal">find()</code> method.
        </p><p>
          To specify the number of documents included in a result set,
          append the <code class="literal">limit()</code> method with a value to
          the <code class="literal">find()</code> method. The following query
          returns the first five documents in the countryinfo
          collection.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find().limit(5)</code></strong>
... [<span class="emphasis"><em>output removed</em></span>]
5 documents in set (0.00 sec)
</pre><p>
          To specify an order for the results, append the
          <code class="literal">sort()</code> method to the
          <code class="literal">find()</code> method. Pass to the
          <code class="literal">sort()</code> method a list of one or more fields
          to sort by and, optionally, the descending
          (<code class="literal">desc</code>) or ascending
          (<code class="literal">asc</code>) attribute as appropriate. Ascending
          order is the default order type.
        </p><p>
          For example, the following query sorts all documents by the
          IndepYear field and then returns the first eight documents in
          descending order.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find().sort(["IndepYear desc"]).limit(8)</code></strong>
... [<span class="emphasis"><em>output removed</em></span>]
8 documents in set (0.00 sec)
</pre><p>
          By default, the <code class="literal">limit()</code> method starts from
          the first document in the collection. You can use the
          <code class="literal">skip()</code> method to change the starting
          document. For example, to ignore the first document and return
          the next eight documents matching the condition, pass to the
          <code class="literal">skip()</code> method a value of 1.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1)</code></strong>
... [<span class="emphasis"><em>output removed</em></span>]
8 documents in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677846784"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              The <a class="link" href="functions.html" title="Chapter 12 Functions and Operators">MySQL Reference
              Manual</a> provides detailed documentation on functions
              and operators.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionfindfunction" target="_top">CollectionFindFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-documents-modify"></a>19.5.4.4 Modify Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">modify()</code> method to update one
        or more documents in a collection. The X DevAPI provides
        additional methods for use with the <code class="literal">modify()</code>
        method to:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            Set and unset fields within documents.
          </p></li><li class="listitem"><p>
            Append, insert, and delete arrays.
          </p></li><li class="listitem"><p>
            Bind, limit, and sort the documents to be modified.
</p></li></ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677835904"></a>Set and Unset Fields</h5>

</div>

</div>

</div>
<p>
          The <code class="literal">modify()</code> method works by filtering a
          collection to include only the documents to be modified and
          then applying the operations that you specify to those
          documents.
        </p><p>
          In the following example, the <code class="literal">modify()</code>
          method uses the search condition to identify the document to
          change and then the <code class="literal">set()</code> method replaces
          two values within the nested demographics object.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.modify("_id = 'SEA'").
set("demographics", {LifeExpectancy: 78, Population: 28})</code></strong>
Query OK, 1 item affected (0.04 sec)
</pre><p>
          After you modify a document, use the <code class="literal">find()</code>
          method to verify the change.
        </p><p>
          To remove content from a document, use the
          <code class="literal">modify()</code> and <code class="literal">unset()</code>
          methods. For example, the following query removes the GNP from
          a document that matches the search condition.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'Sealand'").unset("GNP")</code></strong>
Query OK, 1 item affected (0.01 sec)   
</pre><p>
          Use the <code class="literal">find()</code> method to verify the change.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("Name = 'Sealand'")</code></strong>
[
    {
        "IndepYear": 1967,
        "Name": "Sealand",
        "_id": "SEA",
        "demographics": {
            "LifeExpectancy": 78,
            "Population": 28
        },
        "geography": {
            "Continent": "Europe",
            "Region": "British Islands",
            "SurfaceArea": 193
        },
        "government": {
            "GovernmentForm": "Monarchy",
            "HeadOfState": "Michael Bates"
        }
    }
]
1 document in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677822576"></a>Append, Insert, and Delete Arrays</h5>

</div>

</div>

</div>
<p>
          To append an element to an array field, or insert, or delete
          elements in an array, use the
          <code class="literal">arrayAppend()</code>,
          <code class="literal">arrayInsert()</code>, or
          <code class="literal">arrayDelete()</code> methods. The following
          examples modify the countryinfo collection to enable tracking
          of international airports.
        </p><p>
          The first example uses the <code class="literal">modify()</code> and
          <code class="literal">set()</code> methods to create a new Airports
          field in all documents.
</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Caution
</div>
<p>
            Use care when you modify documents without specifying a
            search condition. This action will modify all documents in
            the collection.
</p>
</div>
<pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.modify("true").set("Airports", [])</code></strong>
Query OK, 240 items affected (0.07 sec)
</pre><p>
          With the Airports field added, the next example uses the
          <code class="literal">arrayAppend()</code> method to add a new airport
          to one of the documents. <span class="emphasis"><em>$.Airports</em></span> in
          the following example represents the Airports field of the
          current document.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'France'").arrayAppend("$.Airports", "ORY")</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre><p>
          Use <strong class="userinput"><code>db.countryinfo.find("Name =
          'France'")</code></strong> to see the change.
        </p><p>
          To insert an element at a different position in the array, use
          the <code class="literal">arrayInsert()</code> method to specify which
          index to insert in the path expression. In this case, the
          index is 0, or the first element in the array.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'France'").arrayInsert("$.Airports[0]", "CDG")</code></strong>
Query OK, 1 item affected (0.04 sec)
</pre><p>
          To delete an element from the array, you must pass to the
          <code class="literal">arrayDelete()</code> method the index of the
          element to be deleted.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.modify("Name = 'France'").arrayDelete("$.Airports[1]")</code></strong>
Query OK, 1 item affected (0.03 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677804544"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              The <a class="link" href="data-types.html#json-paths" title="Searching and Modifying JSON Values">MySQL Reference
              Manual</a> provides instructions to help you search for
              and modify JSON values.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionmodifyfunction" target="_top">CollectionModifyFunction</a>
              for the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-documents-remove"></a>19.5.4.5 Remove Documents</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">remove()</code> method to delete
        some or all documents from a collection in a database. The
        X DevAPI provides additional methods for use with the
        <code class="literal">remove()</code> method to filter and sort the
        documents to be removed.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677796512"></a>Remove Documents Using Conditions</h5>
</div>
</div>
</div>
<p>
          The example that follows passes a search condition to the
          <code class="literal">remove()</code> method. All documents matching the
          condition will be removed from the countryinfo collection. In
          this example, one document matches the condition.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.remove("_id = 'SEA'")</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677792896"></a>Remove the First Document</h5>

</div>

</div>

</div>
<p>
          To remove the first document in the countryinfo collection,
          use the <code class="literal">limit()</code> method with a value of 1.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.remove("true").limit(1)</code></strong>
Query OK, 1 item affected (0.03 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677789408"></a>Remove the Last Document in an Order</h5>

</div>

</div>

</div>
<p>
          The following example removes the last document in the
          countryinfo collection by country name.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.remove("true").sort(["Name desc"]).limit(1)</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677786592"></a>Remove All Documents in a Collection</h5>

</div>

</div>

</div>
<p>
          You can remove all documents in a collection. To do so, use
          the <code class="literal">remove("true")</code> method without
          specifying any search condition.
</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Caution
</div>
<p>
            Use care when you remove documents without specifying a
            search condition. This action will delete all documents from
            the collection.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677783568"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionremovefunction" target="_top">CollectionRemoveFunction</a>
              for the full syntax definition.
            </p></li><li class="listitem"><p>
              See
              <a class="xref" href="document-store.html#mysql-shell-tutorial-javascript-download" title="19.5.2 Import Database Sample">Section 19.5.2, “Import Database Sample”</a>
              for instructions to recreate the
              <code class="literal">world_x</code> database.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-indexes-create"></a>19.5.4.6 Create and Drop Indexes</h4>

</div>

</div>

</div>
<p>
        Indexes are used to find documents with specific field values
        quickly. Without an index, MySQL must begin with the first
        document and then read through the entire collection to find the
        relevant fields. The larger the collection, the more this costs.
        If a collection is large and queries on a specific field are
        common, then consider creating an index on a specific field
        inside a document.
      </p><p>
        For example, the following query will perform better with an
        index:
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.find("demographics.Population &lt; 100")</code></strong>
...[<span class="emphasis"><em>output removed</em></span>]
8 documents in set (0.00 sec)
</pre><p>
        The <code class="literal">createIndex()</code> method creates an index
        that you can define as nonunique or unique. Use the
        <code class="literal">field()</code> method to chain the fields that
        should be indexed. The <code class="literal">execute()</code> method is
        required to create or drop an index.
      </p><p>
        In MySQL, the <code class="literal">_id</code> field is equivalent to a
        primary key by default.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677769824"></a>Add a Nonunique Index</h5>
</div>
</div>
</div>
<p>
          To create a nonunique index, pass to the
          <code class="literal">createIndex()</code> method an index name.
          Duplicate index names are prohibited.
        </p><p>
          In the following example, the first parameter of the
          <code class="literal">field()</code> method specifies the Population
          field inside the demographics object and the next parameter
          indicates that the field should be indexed as an Integer
          numeric value. The last parameter indicates whether the field
          should require the NOT NULL constraint. If the value is
          <code class="literal">false</code>, the field can contain
          <code class="literal">NULL</code> values.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.createIndex("pop").
field("demographics.Population", "INTEGER", false).execute()</code></strong>
Query OK (0.04 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677763328"></a>Add a Unique Index</h5>

</div>

</div>

</div>
<p>
          To create a unique index, pass to the
          <code class="literal">createIndex()</code> method an index name and the
          <code class="literal">mysqlx.IndexType.UNIQUE</code> type. Country
          <code class="literal">"Name"</code> is another common field in the
          countryinfo collection to index. In the following example,
          <code class="literal">"Text(40)"</code> represents the number of
          characters to index and <code class="literal">true</code> indicates that
          the field cannot contain any <code class="literal">NULL</code> values.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.createIndex("name", mysqlx.IndexType.UNIQUE).
field("Name", "TEXT(40)", true).execute()</code></strong>
Query OK (0.04 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677756096"></a>Drop an Index</h5>

</div>

</div>

</div>
<p>
          To drop an index, pass to the <code class="literal">dropIndex()</code>
          method the name of the index to drop. For example, you can
          drop the <span class="quote">“<span class="quote">pop</span>”</span> index as follows:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.countryinfo.dropIndex("pop").execute()</code></strong>
Query OK (0.58 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677752176"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See
              <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-collection-index-management-functions.html" target="_top">Collection Index Management Functions</a>
              for the full syntax definition.

              
</p></li></ul>
</div>

</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-javascript-relational-tables"></a>19.5.5 Relational Tables</h3>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-table-insert">19.5.5.1 Insert Records into Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-table-select">19.5.5.2 Select Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-table-update">19.5.5.3 Update Tables</a></span></dt><dt><span class="section"><a href="document-store.html#mysql-shell-tutorial-javascript-table-delete">19.5.5.4 Delete Tables</a></span></dt></dl>
</div>
<p>
      You can use MySQL Shell to manipulate not just JSON documents,
      but also relational tables.
    </p><p>
      In MySQL, each relational table is associated with a particular
      storage engine. The examples in this section use
      <a class="link" href="innodb-storage-engine.html" title="Chapter 14 The InnoDB Storage Engine"><code class="literal">InnoDB</code></a> tables in the
      <code class="literal">world_x</code> database.
</p>
<h4><a name="idm139684677744080"></a>Confirm the Schema</h4>
<p>
      To show the value that is assigned to the schema variable, type
      <code class="literal">db</code>.
    </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db</code></strong>
</pre><p>
      If the schema value is not <code class="literal">Schema:world_x</code>, then
      set the <code class="literal">db</code> variable as follows:
    </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>\use world_x</code></strong>
</pre>
<h4><a name="idm139684677737648"></a>Show All Tables</h4>
<p>
      To display all relational tables in the <code class="literal">world_x</code>
      database, use the <code class="literal">getTables()</code> method on the
      schema object.
    </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.getTables()</code></strong>
{
    "city": &lt;Table:city&gt;,
    "country": &lt;Table:country&gt;,
    "countrylanguage": &lt;Table:countrylanguage&gt;
}
</pre>
<h4><a name="idm139684677733456"></a>Basic Table Operations</h4>
<p>
      Basic operations scoped by tables include:
</p>
<div class="informaltable">
<table summary="CRUD operations to use interactively on tables within MySQL Shell"><col width="32%"><col width="68%"><thead><tr>
          <th scope="col">Operation form</th>
          <th scope="col">Description</th>
        </tr></thead><tbody><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.insert()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-table-insert" title="19.5.5.1 Insert Records into Tables">insert()</a>
            method inserts one or more records into the named table.</td>
        </tr><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.select()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-table-select" title="19.5.5.2 Select Tables">select()</a>
            method returns some or all records in the named table.</td>
        </tr><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.update()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-table-update" title="19.5.5.3 Update Tables">update()</a>
            method updates records in the named table.</td>
        </tr><tr>
          <td scope="row"><code class="literal">db.<em class="replaceable"><code>name</code></em>.delete()</code></td>
          <td>The
            <a class="link" href="document-store.html#mysql-shell-tutorial-javascript-table-delete" title="19.5.5.4 Delete Tables">delete()</a>
            method deletes one or more records from the named table.</td>
</tr></tbody></table>
</div>
<h4><a name="idm139684677709328"></a>Related Information</h4>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          See
          <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-relational-tables.html" target="_top">Working with Relational Tables</a>
          for a general overview.
        </p></li><li class="listitem"><p>
          <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/mysql-x-crud-ebnf-definitions.html" target="_top">CRUD EBNF Definitions</a> provides a
          complete list of operations.
        </p></li><li class="listitem"><p>
          See <a class="xref" href="document-store.html#mysql-shell-tutorial-javascript-download" title="19.5.2 Import Database Sample">Section 19.5.2, “Import Database Sample”</a>
          for instructions on setting up the <code class="literal">world_x</code>
          database sample.
</p></li></ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-table-insert"></a>19.5.5.1 Insert Records into Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">insert()</code> method with the
        <code class="literal">values()</code> method to insert records into an
        existing relational table. The <code class="literal">insert()</code>
        method accepts individual columns or all columns in the table.
        Use one or more <code class="literal">values()</code> methods to specify
        the values to be inserted.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677697984"></a>Insert a Complete Record</h5>
</div>
</div>
</div>
<p>
          To insert a complete record, pass to the
          <code class="literal">insert()</code> method all columns in the table.
          Then pass to the <code class="literal">values()</code> method one value
          for each column in the table. For example, to add a new record
          to the city table in the <code class="literal">world_x</code> database,
          insert the following record and press <span class="keycap"><strong>Enter</strong></span>
          twice.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.insert("ID", "Name", "CountryCode", "District", "Info").
values(null, "Olympia", "USA", "Washington", '{"Population": 5000}')</code></strong>
Query OK, 1 item affected (0.01 sec)
</pre><p>
          The city table has five columns: ID, Name, CountryCode,
          District, and Info. Each value must match the data type of the
          column it represents.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677691488"></a>Insert a Partial Record</h5>

</div>

</div>

</div>
<p>
          The following example inserts values into the ID, Name, and
          CountryCode columns of the city table.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.insert("ID", "Name", "CountryCode").
values(null, "Little Falls", "USA").values(null, "Happy Valley", "USA")</code></strong>
Query OK, 2 item affected (0.03 sec)
</pre><p>
          When you specify columns using the <code class="literal">insert()</code>
          method, the number of values must match the number of columns.
          In the previous example, you must supply three values to match
          the three columns specified.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677687360"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableinsertfunction" target="_top">TableInsertFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-table-select"></a>19.5.5.2 Select Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">select()</code> method to query for
        and return records from a table in a database. The
        X DevAPI provides additional methods to use with the
        <code class="literal">select()</code> method to filter and sort the
        returned records.
      </p><p>
        MySQL provides the following operators to specify search
        conditions: <code class="literal">OR</code> (<code class="literal">||</code>),
        <code class="literal">AND</code> (<code class="literal">&amp;&amp;</code>),
        <code class="literal">XOR</code>, <code class="literal">IS</code>,
        <code class="literal">NOT</code>, <code class="literal">BETWEEN</code>,
        <code class="literal">IN</code>, <code class="literal">LIKE</code>,
        <code class="literal">!=</code>, <code class="literal">&lt;&gt;</code>,
        <code class="literal">&gt;</code>, <code class="literal">&gt;=</code>,
        <code class="literal">&lt;</code>, <code class="literal">&lt;=</code>,
        <code class="literal">&amp;</code>, <code class="literal">|</code>,
        <code class="literal">&lt;&lt;</code>, <code class="literal">&gt;&gt;</code>,
        <code class="literal">+</code>, <code class="literal">-</code>,
        <code class="literal">*</code>, <code class="literal">/</code>,
        <code class="literal">~</code>, and <code class="literal">%</code>.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677662768"></a>Select All Records</h5>
</div>
</div>
</div>
<p>
          To issue a query that returns all records from an existing
          table, use the <code class="literal">select()</code> method without
          specifying search conditions. The following example selects
          all records from the city table in the
          <code class="literal">world_x</code> database.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
            Limit the use of the empty <code class="literal">select()</code>
            method to interactive statements. Always use explicit
            column-name selections in your application code.
</p>
</div>
<pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select()</code></strong>
+------+------------+-------------+------------+-------------------------+
| ID   | Name       | CountryCode | District   | Info                    |
+------+------------+-------------+------------+-------------------------+
|    1 | Kabul      | AFG         | Kabol      |{"Population": 1780000}  |
|    2 | Qandahar   | AFG         | Qandahar   |{"Population": 237500}   |
|    3 | Herat      | AFG         | Herat      |{"Population": 186800}   |
...    ...          ...           ...          ...
| 4079 | Rafah      | PSE         | Rafah      |{"Population": 92020}    |
+------+------- ----+-------------+------------+-------------------------+
4082 rows in set (0.01 sec)
</pre><p>
          An empty set (no matching records) returns the following
          information:
        </p><pre class="screen">
Empty set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677655024"></a>Filter Searches</h5>

</div>

</div>

</div>
<p>
          To issue a query that returns a set of table columns, use the
          <code class="literal">select()</code> method and specify the columns to
          return between square brackets. This query returns the Name
          and CountryCode columns from the city table.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"])</code></strong>
+-------------------+-------------+
| Name              | CountryCode |
+-------------------+-------------+
| Kabul             | AFG         |
| Qandahar          | AFG         |
| Herat             | AFG         |
| Mazar-e-Sharif    | AFG         |
| Amsterdam         | NLD         |
...                 ...
| Rafah             | PSE         |
| Olympia           | USA         |
| Little Falls      | USA         |
| Happy Valley      | USA         |
+-------------------+-------------+
4082 rows in set (0.00 sec)
</pre><p>
          To issue a query that returns rows matching specific search
          conditions, use the <code class="literal">where()</code> method to
          include those conditions. For example, the following example
          returns the names and country codes of the cities that start
          with the letter Z.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).where("Name like 'Z%'")</code></strong>
+-------------------+-------------+
| Name              | CountryCode |
+-------------------+-------------+
| Zaanstad          | NLD         |
| Zoetermeer        | NLD         |
| Zwolle            | NLD         |
| Zenica            | BIH         |
| Zagazig           | EGY         |
| Zaragoza          | ESP         |
| Zamboanga         | PHL         |
| Zahedan           | IRN         |
| Zanjan            | IRN         |
| Zabol             | IRN         |
| Zama              | JPN         |
| Zhezqazghan       | KAZ         |
| Zhengzhou         | CHN         |
...                 ...
| Zeleznogorsk      | RUS         |
+-------------------+-------------+
59 rows in set (0.00 sec)
</pre><p>
          You can separate a value from the search condition by using
          the <code class="literal">bind()</code> method. For example, instead of
          using "Name = 'Z%' " as the condition, substitute a named
          placeholder consisting of a colon followed by a name that
          begins with a letter, such as <span class="emphasis"><em>name</em></span>. Then
          include the placeholder and value in the
          <code class="literal">bind()</code> method as follows:
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).
              where("Name like :name").bind("name", "Z%")</code></strong>
</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Tip
</div>
<p>
            Within a program, binding enables you to specify
            placeholders in your expressions, which are filled in with
            values before execution and can benefit from automatic
            escaping, as appropriate.
          </p><p>
            Always use binding to sanitize input. Avoid introducing
            values in queries using string concatenation, which can
            produce invalid input and, in some cases, can cause security
            issues.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677641632"></a>Project Results</h5>

</div>

</div>

</div>
<p>
          To issue a query using the <a class="link" href="functions.html#operator_and"><code class="literal">AND</code></a>
          operator, add the operator between search conditions in the
          <code class="literal">where()</code> method.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).
               where("Name like 'Z%' and CountryCode = 'CHN'")</code></strong>
+----------------+-------------+
| Name           | CountryCode |
+----------------+-------------+
| Zhengzhou      | CHN         |
| Zibo           | CHN         |
| Zhangjiakou    | CHN         |
| Zhuzhou        | CHN         |
| Zhangjiang     | CHN         |
| Zigong         | CHN         |
| Zaozhuang      | CHN         |
...              ...
| Zhangjiagang   | CHN         |
+----------------+-------------+
22 rows in set (0.01 sec)
</pre><p>
          To specify multiple conditional operators, you can enclose the
          search conditions in parenthesis to change the operator
          precedence. The following example demonstrates the placement
          of <a class="link" href="functions.html#operator_and"><code class="literal">AND</code></a> and
          <a class="link" href="functions.html#operator_or"><code class="literal">OR</code></a> operators.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["Name", "CountryCode"]).
where("Name like 'Z%' and (CountryCode = 'CHN' or CountryCode = 'RUS')")</code></strong>
+-------------------+-------------+
| Name              | CountryCode |
+-------------------+-------------+
| Zhengzhou         | CHN         |
| Zibo              | CHN         |
| Zhangjiakou       | CHN         |
| Zhuzhou           | CHN         |
...                 ...
| Zeleznogorsk      | RUS         |
+-------------------+-------------+
29 rows in set (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677631616"></a>Limit, Order, and Offset Results</h5>

</div>

</div>

</div>
<p>
          You can apply the <code class="literal">limit()</code>,
          <code class="literal">orderBy()</code>, and <code class="literal">offSet()</code>
          methods to manage the number and order of records returned by
          the <code class="literal">select()</code> method.
        </p><p>
          To specify the number of records included in a result set,
          append the <code class="literal">limit()</code> method with a value to
          the <code class="literal">select()</code> method. For example, the
          following query returns the first five records in the country
          table.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.country.select(["Code", "Name"]).limit(5)</code></strong>
+------+-------------+
| Code | Name        |
+------+-------------+
| ABW  | Aruba       |
| AFG  | Afghanistan |
| AGO  | Angola      |
| AIA  | Anguilla    |
| ALB  | Albania     |
+------+-------------+
5 rows in set (0.00 sec)
</pre><p>
          To specify an order for the results, append the
          <code class="literal">orderBy()</code> method to the
          <code class="literal">select()</code> method. Pass to the
          <code class="literal">orderBy()</code> method a list of one or more
          columns to sort by and, optionally, the descending
          (<code class="literal">desc</code>) or ascending
          (<code class="literal">asc</code>) attribute as appropriate. Ascending
          order is the default order type.
        </p><p>
          For example, the following query sorts all records by the Name
          column and then returns the first three records in descending
          order .
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.country.select(["Code", "Name"]).orderBy(["Name desc"]).limit(3)</code></strong>
+------+------------+
| Code | Name       |
+------+------------+
| ZWE  | Zimbabwe   |
| ZMB  | Zambia     |
| YUG  | Yugoslavia |
+------+------------+
3 rows in set (0.00 sec)
</pre><p>
          By default, the <code class="literal">limit()</code> method starts from
          the first record in the table. You can use the
          <code class="literal">offset()</code> method to change the starting
          record. For example, to ignore the first record and return the
          next three records matching the condition, pass to the
          <code class="literal">offset()</code> method a value of 1.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.country.select(["Code", "Name"]).orderBy(["Name desc"]).limit(3).offset(1)</code></strong>
+------+------------+
| Code | Name       |
+------+------------+
| ZMB  | Zambia     |
| YUG  | Yugoslavia |
| YEM  | Yemen      |
+------+------------+
3 rows in set (0.00 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677612800"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              The <a class="link" href="functions.html" title="Chapter 12 Functions and Operators">MySQL Reference
              Manual</a> provides detailed documentation on functions
              and operators.
            </p></li><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableselectfunction" target="_top">TableSelectFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-table-update"></a>19.5.5.3 Update Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">update()</code> method to modify one
        or more records in a table. The <code class="literal">update()</code>
        method works by filtering a query to include only the records to
        be updated and then applying the operations you specify to those
        records.
      </p><p>
        To replace a city name in the city table, pass to the
        <code class="literal">set()</code> method the new city name. Then, pass to
        the <code class="literal">where()</code> method the city name to locate
        and replace. The following example replaces the city Peking with
        Beijing.
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.update().set("Name", "Beijing").where("Name = 'Peking'")</code></strong>
Query OK, 1 item affected (0.04 sec)
</pre><p>
        Use the <code class="literal">select()</code> method to verify the change.
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).where("Name = 'Beijing'")</code></strong>
+------+-----------+-------------+----------+-----------------------------+
| ID   | Name      | CountryCode | District | Info                        |
+------+-----------+-------------+----------+-----------------------------+
| 1891 | Beijing   | CHN         | Peking   | {"Population": 7472000}     |
+------+-----------+-------------+----------+-----------------------------+
1 row in set (0.00 sec)
</pre>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677598320"></a>Related Information</h5>
</div>
</div>
</div>

<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableupdatefunction" target="_top">TableUpdateFunction</a> for
              the full syntax definition.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="mysql-shell-tutorial-javascript-table-delete"></a>19.5.5.4 Delete Tables</h4>

</div>

</div>

</div>
<p>
        You can use the <code class="literal">delete()</code> method to remove
        some or all records from a table in a database. The
        X DevAPI provides additional methods to use with the
        <code class="literal">delete()</code> method to filter and order the
        records to be deleted.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h5 class="title"><a name="idm139684677592064"></a>Delete Records Using Conditions</h5>
</div>
</div>
</div>
<p>
          The example that follows passes search conditions to the
          <code class="literal">delete()</code> method. All records matching the
          condition will be deleted from the city table. In this
          example, one record matches the condition.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.delete().where("Name = 'Olympia'")</code></strong>
Query OK, 1 item affected (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677588512"></a>Delete the First Record</h5>

</div>

</div>

</div>
<p>
          To delete the first record in the city table, use the
          <code class="literal">limit()</code> method with a value of 1.
        </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.delete().limit(1)</code></strong>
Query OK, 1 item affected (0.02 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677585056"></a>Delete All Records in a Table</h5>

</div>

</div>

</div>
<p>
          You can delete all records in a table. To do so, use the
          <code class="literal">delete()</code> method without specifying a search
          condition.
</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Caution
</div>
<p>
            Use care when you delete records without specifying a search
            condition. This action will delete all records from the
            table.
</p>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title"><a name="idm139684677582032"></a>Related Information</h5>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
              See <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tabledeletefunction" target="_top">TableDeleteFunction</a> for
              the full syntax definition.
            </p></li><li class="listitem"><p>
              See
              <a class="xref" href="document-store.html#mysql-shell-tutorial-javascript-download" title="19.5.2 Import Database Sample">Section 19.5.2, “Import Database Sample”</a>
              for instructions to recreate the
              <code class="literal">world_x</code> database.
</p></li></ul>
</div>

</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="mysql-shell-tutorial-javascript-documents-in-tables"></a>19.5.6 Documents in Tables</h3>

</div>

</div>

</div>
<p>
      In MySQL, a table may contain traditional relational data, JSON
      values, or both. You can combine traditional data with JSON
      documents by storing the documents in columns having a native
      <a class="link" href="data-types.html#json" title="11.6 The JSON Data Type"><code class="literal">JSON</code></a> data type.
    </p><p>
      Examples in this section use the city table in the
      <code class="literal">world_x</code> database.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h4 class="title"><a name="idm139684677572304"></a>city Table Description</h4>
</div>
</div>
</div>
<p>
        The city table has five columns (or fields).
      </p><pre class="screen">
+---------------+------------+-------+-------+---------+------------------+
| Field         | Type       | Null  | Key   | Default | Extra            |
+---------------+------------+-------+-------+---------+------------------+
| ID            | int(11)    | NO    | PRI   | null    | auto_increment   |
| Name          | char(35)   | NO    |       |         |                  |
| CountryCode   | char(3)    | NO    |       |         |                  |
| District      | char(20)   | NO    |       |         |                  |
| Info          | json       | YES   |       | null    |                  |
+---------------+------------+-------+-------+---------+------------------+
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684677569680"></a>Insert a Record</h4>

</div>

</div>

</div>
<p>
        To insert a document into the column of a table, pass to the
        <code class="literal">values()</code> method a well-formed JSON document
        in the correct order. In the following example, a document is
        passed as the final value to be inserted into the Info column.
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.insert().
values(null, "San Francisco", "USA", "California", '{"Population":830000}')</code></strong>
Query OK, 1 item affected (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684677566016"></a>Select a Record</h4>

</div>

</div>

</div>
<p>
        You can issue a query with a search condition that evaluates
        document values in the expression.
      </p><pre class="programlisting">
mysql-js&gt; <strong class="userinput"><code>db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).
  where("CountryCode = :country and Info-&gt;'$.Population' &gt; 1000000").
  bind('country', 'USA')</code></strong>
+------+----------------+-------------+----------------+-----------------------------+
| ID   | Name           | CountryCode | District       | Info                        |
+------+----------------+-------------+----------------+-----------------------------+
| 3793 | New York       | USA         | New York       | {"Population": 8008278}     |
| 3794 | Los Angeles    | USA         | California     | {"Population": 3694820}     |
| 3795 | Chicago        | USA         | Illinois       | {"Population": 2896016}     |
| 3796 | Houston        | USA         | Texas          | {"Population": 1953631}     |
| 3797 | Philadelphia   | USA         | Pennsylvania   | {"Population": 1517550}     |
| 3798 | Phoenix        | USA         | Arizona        | {"Population": 1321045}     |
| 3799 | San Diego      | USA         | California     | {"Population": 1223400}     |
| 3800 | Dallas         | USA         | Texas          | {"Population": 1188580}     |
| 3801 | San Antonio    | USA         | Texas          | {"Population": 1144646}     |
+------+----------------+-------------+----------------+-----------------------------+
9 rows in set (0.01 sec)
</pre>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title"><a name="idm139684677560784"></a>Related Information</h4>

</div>

</div>

</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
            See
            <a class="ulink" href="http://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-relational-tables-and-documents.html" target="_top">Working with Relational Tables and Documents</a>
            for a general overview.
          </p></li><li class="listitem"><p>
            See <a class="xref" href="data-types.html#json" title="11.6 The JSON Data Type">Section 11.6, “The JSON Data Type”</a> for a detailed description of the
            data type.
</p></li></ul>
</div>

</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="mysql-shell-visual-studio"></a>19.6 Quick-Start Guide: MySQL for Visual Studio</h2>

</div>

</div>

</div>
<p>
    This section explains how to use MySQL Shell to script a server
    using MySQL for Visual Studio.
</p>
<div class="simplesect">

<div class="titlepage">
<div>

<div class="simple">
<h3 class="title"><a name="mysql-shell-visual-studio-introduction"></a>Introduction</h3>
</div>
</div>
</div>
<p>
      MySQL for Visual Studio provides access to MySQL objects and data without forcing
      developers to leave Visual Studio. Designed and developed as a
      Visual Studio package, MySQL for Visual Studio integrates directly into Server
      Explorer providing a seamless experience for setting up new
      connections and working with database objects.
    </p><p>
      The following MySQL for Visual Studio features are available as of version 2.0.2:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          JavaScript and Python code editors, where scripts in those
          languages can be executed to query data from a MySQL database.
        </p></li><li class="listitem"><p>
          Better integration with the Server Explorer to open MySQL,
          JavaScript, and Python code editors directly from a connected
          MySQL instance.
        </p></li><li class="listitem"><p>
          A newer user interface for displaying query results, where
          different views are presented from result sets returned by a
          MySQL Server like:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
              Multiple tabs for each result set returned by an executed
              query.
            </p></li><li class="listitem"><p>
              Results view, where the information can be seen in grid,
              tree, or text representation for JSON results.
            </p></li><li class="listitem"><p>
              Field types view, where information about the columns of a
              result set is shown, such as names, data types, character
              sets, and more.
            </p></li><li class="listitem"><p>
              Query statistics view, displaying information about the
              executed query such as execution times, processed rows,
              index and temporary tables usage, and more.
            </p></li><li class="listitem"><p>
              Execution plan view, displaying an explanation of the
              query execution done internally by the MySQL Server.
</p></li></ul>
</div>
</li></ul>
</div>

</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="mysql-shell-visual-studio-getting-started"></a>Getting Started</h3>

</div>

</div>

</div>
<p>
      The requirements are MySQL for Visual Studio 2.0.2 or higher, and Visual Studio
      2010 or higher. X DevAPI support requires MySQL Server 5.7.12 or
      higher with the X plugin enabled.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="mysql-shell-visual-studio-code-editor-open"></a>Opening a Code Editor</h3>

</div>

</div>

</div>
<p>
      Before opening a code editor that can execute queries against a
      MySQL server, a connection needs to be established:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1"><li class="listitem"><p>
          Open the Server Explorer pane through the View menu, or with
          <span class="keycap"><strong>Control</strong></span> + <span class="keycap"><strong>W</strong></span>,
          <span class="keycap"><strong>K</strong></span>.
        </p></li><li class="listitem"><p>
          Right-click on the Data Connections node, select <span class="guilabel">Add
          Connection...</span>.
        </p></li><li class="listitem"><p>
          In the <span class="guilabel">Add Connection</span> dialog, make sure
          the MySQL Data Provider is being used and fill in all the
          information.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
            To enter the port number, click
            <span class="guibutton">Advanced...</span> and set the Port among
            the list of connection properties.
</p>
</div>
</li><li class="listitem"><p>
          Click <span class="guibutton">Test Connection</span> to ensure you
          have a valid connection, then click <span class="guibutton">OK</span>.
        </p></li><li class="listitem"><p>
          Right-click your newly created connection, select <span class="guimenu">New
          MySQL Script</span> and then the language for the code
          editor you want to open.
</p></li></ol>
</div>
<p>
      For existing MySQL connections, to create a new editor you need
      only to do the last step.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title"><a name="mysql-shell-visual-studio-code-editor-using"></a>Using the Code Editor</h3>

</div>

</div>

</div>
<p>
      The MySQL script editors have a toolbar at the start where
      information about the session is displayed, along with the actions
      that can be executed.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
        Note the first two buttons in the toolbar represent a way to
        connect or disconnect from a MySQL server. If the editor was
        opened from the Server Explorer, the connection will be already
        established for the new editor window.
</p>
</div>
<p>
      The third button is the <span class="guibutton">Run</span> button, the
      script contained in the editor window is executed by clicking it
      and results from the script execution are displayed below the
      script window.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">

<div class="admon-title">
Note
</div>
<p>
        Some commands in the MySQL Shell can be executed without
        appending <span class="command"><strong>execute()</strong></span> while in interactive
        mode. In MySQL for Visual Studio, these commands do require
        <span class="command"><strong>execute()</strong></span>. In other words, append
        ".execute()" to execute commands.
</p>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a name="x-plugin"></a>19.7 X Plugin</h2>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#x-plugin-ssl-connections">19.7.1 Using Secure Connections with X Plugin</a></span></dt><dt><span class="section"><a href="document-store.html#x-plugin-options-variables">19.7.2 X Plugin Options and Variables</a></span></dt><dt><span class="section"><a href="document-store.html#x-plugin-system-monitoring">19.7.3 Monitoring X Plugin</a></span></dt></dl>
</div>
<a class="indexterm" name="idm139684677517040"></a><p>
    This section explains how to configure and monitor the
    X Plugin.
</p>
<div class="section">

<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="x-plugin-ssl-connections"></a>19.7.1 Using Secure Connections with X Plugin</h3>
</div>
</div>
</div>
<p>
      This section explains how to configure X Plugin to use
      secure connections. For more background information, see
      <a class="xref" href="security.html#encrypted-connections" title="6.4 Using Encrypted Connections">Section 6.4, “Using Encrypted Connections”</a>.
    </p><p>
      X Plugin has its own SSL settings which can differ from
      those used with MySQL Server. This means that X Plugin can
      be configured with a different SSL key, certificate, and
      certificate authorities file than MySQL Server. Similarly,
      X Plugin has its own SSL status variables calculated
      independently from the MySQL Server SSL related variables. By
      default the X Plugin SSL configuration is taken from the
      <code class="literal">mysqlx_ssl_*</code> variables, described at
      <a class="xref" href="document-store.html#x-plugin-system-variables-options" title="19.7.2.2 X Plugin System Variables and Options">Section 19.7.2.2, “X Plugin System Variables and Options”</a>. If no
      configuration is provided using the
      <code class="literal">mysqlx_ssl_*</code> variables, X Plugin falls
      back to using the MySQL Server SSL system variables. This means
      you can choose to either have separate SSL configurations for
      MySQL Protocol and X Protocol connections by configuring
      each separately, or share the SSL configuration between MySQL
      Protocol and X Protocol connections by only configuring the
      <code class="literal">ssl-*</code> variables.
    </p><p>
      On a server with X Plugin installed, to configure MySQL
      Protocol and X Protocol connections with separate SSL
      configurations use both the <code class="literal">ssl-*</code> and
      <code class="literal">mysqlx-ssl-*</code> variables in
      <code class="filename">my.cnf</code>:
    </p><pre data-lang="ini" class="programlisting">
[mysqld]
ssl-ca=ca1.pem
ssl-cert=server-cert1.pem
ssl-key=server-key1.pem

mysqlx-ssl-ca=ca2.pem
mysqlx-ssl-cert=server-cert2.pem
mysqlx-ssl-key=server-key2.pem
</pre><p>
      The available <code class="literal">mysqlx_ssl_*</code> variables mirror the
      SSL variables in MySQL Server, so the files and techniques
      described for configuring MySQL Server to use SSL at
      <a class="xref" href="security.html#using-encrypted-connections" title="6.4.1 Configuring MySQL to Use Encrypted Connections">Section 6.4.1, “Configuring MySQL to Use Encrypted Connections”</a> are relevant to
      configuring X Plugin to use secure connections.
    </p><p>
      You can configure the TLS versions used by X Protocol SSL
      connections using the <a class="link" href="server-administration.html#sysvar_tls_version"><code class="literal">tls_version</code></a>
      system variable. The TLS version used by MySQL Protocol and
      X Protocol connections is therefore the same TLS version.
    </p><p>
      Encryption per connection is optional, but a specific user can be
      forced to use encryption for X Protocol and MySQL Protocol
      connections. You configure such a user by issuing a
      <a class="link" href="sql-syntax.html#grant" title="13.7.1.4 GRANT Syntax"><code class="literal">GRANT</code></a> statement with the
      <code class="literal">REQUIRE</code> option. For more details see
      <a class="xref" href="sql-syntax.html#grant" title="13.7.1.4 GRANT Syntax">Section 13.7.1.4, “GRANT Syntax”</a>. Alternatively all X Protocol and
      MySQL Protocol connections can be forced to use encryption by
      setting <a class="link" href="server-administration.html#sysvar_require_secure_transport"><code class="literal">require_secure_transport</code></a>.
</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="x-plugin-options-variables"></a>19.7.2 X Plugin Options and Variables</h3>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#x-plugin-option-variable-reference">19.7.2.1 X Plugin Option and Variable Reference</a></span></dt><dt><span class="section"><a href="document-store.html#x-plugin-system-variables-options">19.7.2.2 X Plugin System Variables and Options</a></span></dt></dl>
</div>
<p>
      This section describes the command options and system variables
      which configure X Plugin. If values specified at startup
      time are incorrect, X Plugin could fail to initialize
      properly and the server does not load it. In this case, the server
      could also produce error messages for other X Plugin
      settings because it cannot recognize them.
</p>
<div class="section">

<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="x-plugin-option-variable-reference"></a>19.7.2.1 X Plugin Option and Variable Reference</h4>
</div>
</div>
</div>
<p>
        This table provides an overview of the command options, and
        system and status variables provided by X Plugin.
</p>
<div class="table">
<a name="idm139684677492624"></a><p class="title"><b>Table 19.1 X Plugin Option and Variable
Reference</b></p>
<div class="table-contents">
<table frame="box" rules="all" summary="Reference for X Plugin command-line options, system variables, and status variables."><col width="20%"><col width="15%"><col width="15%"><col width="15%"><col width="15%"><col width="15%"><col width="15%"><thead><tr><th scope="col">Name</th>
<th scope="col">Cmd-Line</th>
<th scope="col">Option File</th>
<th scope="col">System Var</th>
<th scope="col">Status Var</th>
<th scope="col">Var Scope</th>
<th scope="col">Dynamic</th>
</tr></thead><tbody><tr><td scope="row">Mysqlx_aborted_clients</td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_address">Mysqlx_address</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-bind-address">mysqlx-bind-address</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_bind_address">mysqlx_bind_address</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_bytes_received">Mysqlx_bytes_received</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_bytes_sent">Mysqlx_bytes_sent</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-connect-timeout">mysqlx-connect-timeout</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_connect_timeout">mysqlx_connect_timeout</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_connection_accept_errors">Mysqlx_connection_accept_errors</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_connection_errors">Mysqlx_connection_errors</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_connections_accepted">Mysqlx_connections_accepted</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_connections_closed">Mysqlx_connections_closed</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_connections_rejected">Mysqlx_connections_rejected</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_create_view">Mysqlx_crud_create_view</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_delete">Mysqlx_crud_delete</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_drop_view">Mysqlx_crud_drop_view</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_find">Mysqlx_crud_find</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_insert">Mysqlx_crud_insert</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_modify_view">Mysqlx_crud_modify_view</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_crud_update">Mysqlx_crud_update</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_errors_sent">Mysqlx_errors_sent</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row">Mysqlx_errors_unknown_message_type</td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_expect_close">Mysqlx_expect_close</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_expect_open">Mysqlx_expect_open</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-idle-worker-thread-timeout">mysqlx-idle-worker-thread-timeout</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_idle_worker_thread_timeout">mysqlx_idle_worker_thread_timeout</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_init_error">Mysqlx_init_error</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-max-allowed-packet">mysqlx-max-allowed-packet</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_max_allowed_packet">mysqlx_max_allowed_packet</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-max-connections">mysqlx-max-connections</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_max_connections">mysqlx_max_connections</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-min-worker-threads">mysqlx-min-worker-threads</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_min_worker_threads">mysqlx_min_worker_threads</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>Yes</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_notice_other_sent">Mysqlx_notice_other_sent</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_notice_warning_sent">Mysqlx_notice_warning_sent</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_port">Mysqlx_port</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-port">mysqlx-port</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_port">mysqlx_port</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-port-open-timeout">mysqlx-port-open-timeout</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_port_open_timeout">mysqlx_port_open_timeout</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_rows_sent">Mysqlx_rows_sent</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_sessions">Mysqlx_sessions</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_sessions_accepted">Mysqlx_sessions_accepted</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_sessions_closed">Mysqlx_sessions_closed</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_sessions_fatal_error">Mysqlx_sessions_fatal_error</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_sessions_killed">Mysqlx_sessions_killed</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_sessions_rejected">Mysqlx_sessions_rejected</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_socket">Mysqlx_socket</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-socket">mysqlx-socket</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#sysvar_mysqlx_socket">mysqlx_socket</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_accept_renegotiates">Mysqlx_ssl_accept_renegotiates</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_accepts">Mysqlx_ssl_accepts</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_active">Mysqlx_ssl_active</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-ca">mysqlx-ssl-ca</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-capath">mysqlx-ssl-capath</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-cert">mysqlx-ssl-cert</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_cipher">Mysqlx_ssl_cipher</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-cipher">mysqlx-ssl-cipher</a></td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_cipher_list">Mysqlx_ssl_cipher_list</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-crl">mysqlx-ssl-crl</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-crlpath">mysqlx-ssl-crlpath</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_ctx_verify_depth">Mysqlx_ssl_ctx_verify_depth</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_ctx_verify_mode">Mysqlx_ssl_ctx_verify_mode</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_finished_accepts">Mysqlx_ssl_finished_accepts</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-key">mysqlx-ssl-key</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_server_not_after">Mysqlx_ssl_server_not_after</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_server_not_before">Mysqlx_ssl_server_not_before</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_verify_depth">Mysqlx_ssl_verify_depth</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_verify_mode">Mysqlx_ssl_verify_mode</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_ssl_version">Mysqlx_ssl_version</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_create_collection">Mysqlx_stmt_create_collection</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_create_collection_index">Mysqlx_stmt_create_collection_index</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_disable_notices">Mysqlx_stmt_disable_notices</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_drop_collection">Mysqlx_stmt_drop_collection</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_drop_collection_index">Mysqlx_stmt_drop_collection_index</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_enable_notices">Mysqlx_stmt_enable_notices</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_ensure_collection">Mysqlx_stmt_ensure_collection</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_execute_mysqlx">Mysqlx_stmt_execute_mysqlx</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_execute_sql">Mysqlx_stmt_execute_sql</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_execute_xplugin">Mysqlx_stmt_execute_xplugin</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_kill_client">Mysqlx_stmt_kill_client</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_list_clients">Mysqlx_stmt_list_clients</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_list_notices">Mysqlx_stmt_list_notices</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_list_objects">Mysqlx_stmt_list_objects</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_stmt_ping">Mysqlx_stmt_ping</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Both</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_worker_threads">Mysqlx_worker_threads</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr><tr><td scope="row"><a class="link" href="document-store.html#statvar_Mysqlx_worker_threads_active">Mysqlx_worker_threads_active</a></td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
<td>Global</td>
<td>No</td>
</tr></tbody></table>
</div>

</div>
<br class="table-break">
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="x-plugin-system-variables-options"></a>19.7.2.2 X Plugin System Variables and Options</h4>

</div>

</div>

</div>
<p>
        The following command options configure X Plugin:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><a name="option_mysqld_mysqlx-bind-address"></a>
            <a class="indexterm" name="idm139684676879520"></a>

            <a class="indexterm" name="idm139684676878480"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-bind-address"><code class="option">--mysqlx-bind-address[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-bind-address"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-bind-address=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.17</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_bind_address">mysqlx_bind_address</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>string</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">*</code></td>
</tr></tbody></table>
</div>
<p>
            Specifies the network address which X Plugin uses for
            connections. The equivalent of
            <a class="link" href="server-administration.html#sysvar_bind_address"><code class="literal">bind_address</code></a> for
            X Plugin.
          </p><p>
            By default X Plugin listens for connections on a
            single IPv4 TCP/IP network socket. Use this option to
            configure where X Plugin listens for connections, such
            as binding to an IPv6 address, all IPv4 and IPv6 addresses
            or a default IPv6 address with a fallback IPv4 address.
          </p><p>
            X Plugin treats different types of addresses as
            follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
                If the address is <code class="literal">*</code>, X Plugin
                accepts TCP/IP connections on all server host IPv6 and
                IPv4 interfaces if the server host supports IPv6, or
                accepts TCP/IP connections on all IPv4 addresses
                otherwise. Use this address to permit both IPv4 and IPv6
                connections on all server interfaces. This value is the
                default.
              </p></li><li class="listitem"><p>
                If the address is <code class="literal">0.0.0.0</code>,
                X Plugin accepts TCP/IP connections on all server
                host IPv4 interfaces. This value is the default.
              </p></li><li class="listitem"><p>
                If the address is <code class="literal">::</code>, X Plugin
                accepts TCP/IP connections on all server host IPv4 and
                IPv6 interfaces.
              </p></li><li class="listitem"><p>
                If the address is <code class="literal">*</code>, X Plugin
                accepts TCP/IP connections on all server host IPv6 and
                IPv4 interfaces if the server host supports IPv6, or
                accepts TCP/IP connections on all IPv4 addresses
                otherwise. Use this address to permit both IPv4 and IPv6
                connections for X Plugin.
              </p></li><li class="listitem"><p>
                If the address is an IPv4-mapped address, X Plugin
                accepts TCP/IP connections for that address, in either
                IPv4 or IPv6 format. For example, if X Plugin is
                bound to <code class="literal">::ffff:127.0.0.1</code>, a client
                such as MySQL Shell can connect using
                <code class="option">--host=127.0.0.1</code> or
                <code class="option">--host=::ffff:127.0.0.1</code>.
              </p></li><li class="listitem"><p>
                If the address is a <span class="quote">“<span class="quote">regular</span>”</span> IPv4 or IPv6
                address (such as <code class="literal">127.0.0.1</code> or
                <code class="literal">::1</code>), X Plugin accepts TCP/IP
                connections only for that IPv4 or IPv6 address.
</p></li></ul>
</div>
</li><li class="listitem"><p><a name="option_mysqld_mysqlx-connect-timeout"></a>
            <a class="indexterm" name="idm139684676832016"></a>

            <a class="indexterm" name="idm139684676830976"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-connect-timeout"><code class="option">--mysqlx-connect-timeout[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-connect-timeout"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-connect-timeout=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_connect_timeout">mysqlx_connect_timeout</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">30</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">1000000000</code></td>
</tr></tbody></table>
</div>
<p>
            Number of seconds X Plugin waits for the first packet
            to be received from newly connected clients. The
            X Plugin equivalent of
            <a class="link" href="server-administration.html#sysvar_connect_timeout"><code class="literal">connect_timeout</code></a>.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-idle-worker-thread-timeout"></a>
            <a class="indexterm" name="idm139684676795072"></a>

            <a class="indexterm" name="idm139684676794032"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-idle-worker-thread-timeout"><code class="option">--mysqlx-idle-worker-thread-timeout[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-idle-worker-thread-timeout"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-idle-worker-thread-timeout=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_idle_worker_thread_timeout">mysqlx_idle_worker_thread_timeout</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">60</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">0</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">3600</code></td>
</tr></tbody></table>
</div>
<p>
            Time in seconds after which an idle worker thread is
            terminated.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-max-allowed-packet"></a>
            <a class="indexterm" name="idm139684676759376"></a>

            <a class="indexterm" name="idm139684676758336"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-max-allowed-packet"><code class="option">--mysqlx-max-allowed-packet[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-max-allowed-packet"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-max-allowed-packet=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_max_allowed_packet">mysqlx_max_allowed_packet</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">1048576</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">512</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">1073741824</code></td>
</tr></tbody></table>
</div>
<p>
            Maxmum size of a network packet that X Plugin can
            process.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-max-connections"></a>
            <a class="indexterm" name="idm139684676723712"></a>

            <a class="indexterm" name="idm139684676722672"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-max-connections"><code class="option">--mysqlx-max-connections[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-max-connections"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-max-connections=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_max_connections">mysqlx_max_connections</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">100</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">65535</code></td>
</tr></tbody></table>
</div>
<p>
            Maximum number of concurrent client connections the
            X Plugin can accept. When modifying this variable, if
            the new value is smaller than the current number of
            connections, the new limit is only taken into account for
            new connections.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-min-worker-threads"></a>
            <a class="indexterm" name="idm139684676687920"></a>

            <a class="indexterm" name="idm139684676686880"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-min-worker-threads"><code class="option">--mysqlx-min-worker-threads[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-min-worker-threads"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-min-worker-threads=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.12</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_min_worker_threads">mysqlx_min_worker_threads</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">2</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">100</code></td>
</tr></tbody></table>
</div>
<p>
            The minimum number of worker threads the X Plugin uses
            for handling client requests.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-port"></a>
            <a class="indexterm" name="idm139684676649600"></a>

            <a class="indexterm" name="idm139684676648528"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-port"><code class="option">--mysqlx-port[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-port"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-port=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_port">mysqlx_port</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">33060</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">65535</code></td>
</tr></tbody></table>
</div>
<p>
            Specifies the port where the X Plugin listens for
            connections. The equivalent of
            <a class="link" href="server-administration.html#sysvar_port"><code class="literal">port</code></a> for X Plugin.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-port-open-timeout"></a>
            <a class="indexterm" name="idm139684676612800"></a>

            <a class="indexterm" name="idm139684676611760"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-port-open-timeout"><code class="option">--mysqlx-port-open-timeout[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-port-open-timeout"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-port-open-timeout=#</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.17</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_port_open_timeout">mysqlx_port_open_timeout</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">0</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">120</code></td>
</tr></tbody></table>
</div>
<p>
            The amount of time in seconds which X Plugin waits for
            a TCP/IP port to become free.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-socket"></a>
            <a class="indexterm" name="idm139684676574496"></a>

            <a class="indexterm" name="idm139684676573424"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-socket"><code class="option">--mysqlx-socket[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-socket"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-socket=file_name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.15</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_socket">mysqlx_socket</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>string</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">/tmp/mysqlx.sock</code></td>
</tr></tbody></table>
</div>
<p>
            The path to a Unix socket file which X Plugin uses for
            connections. Only used by MySQL Server when running on Unix
            operating systems. Clients can then use this socket to
            connect to MySQL Server using the X Plugin.
          </p><p>
            The value of <a class="link" href="document-store.html#sysvar_mysqlx_socket"><code class="literal">mysqlx_socket</code></a>
            depends on the value of
            <a class="link" href="server-administration.html#sysvar_socket"><code class="literal">socket</code></a>. By default
            <a class="link" href="server-administration.html#sysvar_socket"><code class="literal">socket</code></a> is
            <code class="literal">/tmp/mysql.sock</code> and therefore
            <a class="link" href="document-store.html#sysvar_mysqlx_socket"><code class="literal">mysqlx_socket</code></a> is
            <code class="literal">/tmp/mysqlx.sock</code>. If
            <a class="link" href="server-administration.html#sysvar_socket"><code class="literal">socket</code></a> is set to
            <code class="literal">/sockets/mysql.sock</code> and
            <a class="link" href="document-store.html#sysvar_mysqlx_socket"><code class="literal">mysqlx_socket</code></a> has not been
            manually configured, then
            <a class="link" href="document-store.html#sysvar_mysqlx_socket"><code class="literal">mysqlx_socket</code></a> is set to
            <code class="literal">/sockets/mysqlx.sock</code>. In other words the
            path and filename of <a class="link" href="server-administration.html#sysvar_socket"><code class="literal">socket</code></a>
            is used and an <code class="literal">x</code> is appended to the
            filename, this enables you to conveniently store the sockets
            used by MySQL server at a single path. To define separate
            paths or unique filenames for the MySQL and X Plugin
            sockets, configure both the
            <a class="link" href="server-administration.html#sysvar_socket"><code class="literal">socket</code></a> and the
            <a class="link" href="document-store.html#sysvar_mysqlx_socket"><code class="literal">mysqlx_socket</code></a> system
            variables. For example in a configuration file:
          </p><pre data-lang="ini" class="programlisting">
socket=/home/sockets/mysqld/mysql.sock
mysqlx_socket=/home/sockets/xplugin/xplugin.sock
</pre><p>
            Alternatively, X Plugin can be configured at compile
            time to use a specific socket with the
            <a class="link" href="installing.html#option_cmake_mysqlx_unix_addr"><code class="option">MYSQLX_UNIX_ADDR</code></a> option. If
            the X Plugin
            <a class="link" href="installing.html#option_cmake_mysqlx_unix_addr"><code class="option">MYSQLX_UNIX_ADDR</code></a> compile
            option is not set, the value is based on the
            <a class="link" href="installing.html#option_cmake_mysql_unix_addr"><code class="option">MYSQL_UNIX_ADDR</code></a> and adds an
            <code class="literal">x</code> to the file name, for example resulting
            in <code class="literal">/tmp/mysqlx.sock</code>.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-ca"></a>
            <a class="indexterm" name="idm139684676519056"></a>

            <a class="indexterm" name="idm139684676517984"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-ca"><code class="option">--mysqlx-ssl-ca[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-ca"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-ca=file-name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal">mysqlx_ssl_ca</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>file name</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of <a class="link" href="server-administration.html#sysvar_ssl_ca"><code class="literal">ssl_ca</code></a>
            for X Plugin, see that variable for more information.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-capath"></a>
            <a class="indexterm" name="idm139684676492016"></a>

            <a class="indexterm" name="idm139684676490976"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-capath"><code class="option">--mysqlx-ssl-capath[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-capath"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-capath=dir_name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal">mysqlx_ssl_capath</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>directory name</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of
            <a class="link" href="server-administration.html#sysvar_ssl_capath"><code class="literal">ssl_capath</code></a> for
            X Plugin, see that variable for more information.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-cert"></a>
            <a class="indexterm" name="idm139684676465008"></a>

            <a class="indexterm" name="idm139684676463936"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-cert"><code class="option">--mysqlx-ssl-cert[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-cert"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-cert=name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal">mysqlx_ssl_cert</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>file name</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of <a class="link" href="server-administration.html#sysvar_ssl_cert"><code class="literal">ssl_cert</code></a>
            for X Plugin, see that variable for more information.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-cipher"></a>
            <a class="indexterm" name="idm139684676437984"></a>

            <a class="indexterm" name="idm139684676436944"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-cipher"><code class="option">--mysqlx-ssl-cipher[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-cipher"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-cipher=name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>string</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of
            <a class="link" href="server-administration.html#sysvar_ssl_cipher"><code class="literal">ssl_cipher</code></a> for
            X Plugin, see that variable for more information.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-crl"></a>
            <a class="indexterm" name="idm139684676419344"></a>

            <a class="indexterm" name="idm139684676418272"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-crl"><code class="option">--mysqlx-ssl-crl[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-crl"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-crl=file_name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal">mysqlx_ssl_crl</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>file name</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of <a class="link" href="server-administration.html#sysvar_ssl_crl"><code class="literal">ssl_crl</code></a>
            for X Plugin, see that variable for more information.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-crlpath"></a>
            <a class="indexterm" name="idm139684676392304"></a>

            <a class="indexterm" name="idm139684676391264"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-crlpath"><code class="option">--mysqlx-ssl-crlpath[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-crlpath"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-crlpath=directory_name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal">mysqlx_ssl_crlpath</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>directory name</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of
            <a class="link" href="server-administration.html#sysvar_ssl_crlpath"><code class="literal">ssl_crlpath</code></a> for
            X Plugin, see that variable for more information.
          </p></li><li class="listitem"><p><a name="option_mysqld_mysqlx-ssl-key"></a>
            <a class="indexterm" name="idm139684676365232"></a>

            <a class="indexterm" name="idm139684676364160"></a>

            <a class="link" href="document-store.html#option_mysqld_mysqlx-ssl-key"><code class="option">--mysqlx-ssl-key[=<em class="replaceable"><code>value</code></em>]</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx-ssl-key"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-ssl-key=file-name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal">mysqlx_ssl_key</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>file name</td>
</tr></tbody></table>
</div>
<p>
            The equivalent of <a class="link" href="server-administration.html#sysvar_ssl_key"><code class="literal">ssl_key</code></a>
            for X Plugin, see that variable for more information.
</p></li></ul>
</div>
<p>
        When X Plugin is running the following system variables
        are available.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><a name="sysvar_mysqlx_bind_address"></a>
            <a class="indexterm" name="idm139684676337312"></a>

            <a class="indexterm" name="idm139684676336272"></a>

            <a class="link" href="document-store.html#sysvar_mysqlx_bind_address"><code class="literal">mysqlx_bind_address</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_bind_address"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-bind-address=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_bind_address">mysqlx_bind_address</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>string</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">*</code></td>
</tr></tbody></table>
</div>
<p>
            The network address which X Plugin uses for
            connections. The equivalent of
            <a class="link" href="server-administration.html#sysvar_bind_address"><code class="literal">bind_address</code></a> for
            X Plugin, see that variable for more information. This
            variable is not dynamic and can only be configured at start
            up.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_connect_timeout"></a>
            <a class="indexterm" name="idm139684676306608"></a>

            <a class="indexterm" name="idm139684676305568"></a>

            <a class="link" href="document-store.html#sysvar_mysqlx_connect_timeout"><code class="literal">mysqlx_connect_timeout</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_connect_timeout"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-connect-timeout=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_connect_timeout">mysqlx_connect_timeout</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">30</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">1000000000</code></td>
</tr></tbody></table>
</div>
<p>
            Number of seconds X Plugin waits for the first packet
            to be received from newly connected clients. The equivalent
            of <a class="link" href="server-administration.html#sysvar_connect_timeout"><code class="literal">connect_timeout</code></a> for
            X Plugin.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_idle_worker_thread_timeout"></a>
            <a class="indexterm" name="idm139684676269888"></a>

            <a class="indexterm" name="idm139684676268848"></a>

            <a class="link" href="document-store.html#sysvar_mysqlx_idle_worker_thread_timeout"><code class="literal">mysqlx_idle_worker_thread_timeout</code></a>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_idle_worker_thread_timeout"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-idle-worker-thread-timeout=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_idle_worker_thread_timeout">mysqlx_idle_worker_thread_timeout</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">60</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">0</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">3600</code></td>
</tr></tbody></table>
</div>
<p>
            Number of seconds after which an idle worker thread is
            terminated.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_max_allowed_packet"></a>
            <a class="link" href="document-store.html#sysvar_mysqlx_max_allowed_packet"><code class="literal">mysqlx_max_allowed_packet</code></a>
</p><a class="indexterm" name="idm139684676233056"></a><a class="indexterm" name="idm139684676231952"></a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_max_allowed_packet"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-max-allowed-packet=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.12</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_max_allowed_packet">mysqlx_max_allowed_packet</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">1048576</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">512</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">1073741824</code></td>
</tr></tbody></table>
</div>
<p>
            Maximum size of a network packet that can be received by
            X Plugin. The X Plugin equivalent of
            <a class="link" href="server-administration.html#sysvar_max_allowed_packet"><code class="literal">max_allowed_packet</code></a>.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_min_worker_threads"></a>
            <a class="link" href="document-store.html#sysvar_mysqlx_min_worker_threads"><code class="literal">mysqlx_min_worker_threads</code></a>
</p><a class="indexterm" name="idm139684676193536"></a><a class="indexterm" name="idm139684676192432"></a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_min_worker_threads"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-min-worker-threads=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_min_worker_threads">mysqlx_min_worker_threads</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">2</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">100</code></td>
</tr></tbody></table>
</div>
<p>
            Minimum number of worker threads the X Plugin uses for
            handling client requests.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_max_connections"></a>
            <a class="link" href="document-store.html#sysvar_mysqlx_max_connections"><code class="literal">mysqlx_max_connections</code></a>
</p><a class="indexterm" name="idm139684676158080"></a><a class="indexterm" name="idm139684676157040"></a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_max_connections"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-max-connections=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_max_connections">mysqlx_max_connections</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>Yes</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">100</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">65535</code></td>
</tr></tbody></table>
</div>
<p>
            Maximum number of concurrent client connections
            X Plugin can accept. The X Plugin equivalent of
            <a class="link" href="server-administration.html#sysvar_max_connections"><code class="literal">max_connections</code></a>.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_port"></a>
            <a class="link" href="document-store.html#sysvar_mysqlx_port"><code class="literal">mysqlx_port</code></a>
</p><a class="indexterm" name="idm139684676121568"></a><a class="indexterm" name="idm139684676120480"></a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_port"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-port=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.12</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_port">mysqlx_port</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">33060</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">1</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">65535</code></td>
</tr></tbody></table>
</div>
<p>
            The network port which X Plugin uses for connections.
            The X Plugin equivalent of
            <a class="link" href="server-administration.html#sysvar_port"><code class="literal">port</code></a>.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_port_open_timeout"></a>
            <a class="link" href="document-store.html#sysvar_mysqlx_port_open_timeout"><code class="literal">mysqlx_port_open_timeout</code></a>
</p><a class="indexterm" name="idm139684676082208"></a><a class="indexterm" name="idm139684676081104"></a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_port_open_timeout"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-port-open-timeout=value</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.12</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_port_open_timeout">mysqlx_port_open_timeout</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>integer</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">0</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Minimum Value</strong></span></td>
<td><code class="literal">0</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Maximum Value</strong></span></td>
<td><code class="literal">100</code></td>
</tr></tbody></table>
</div>
<p>
            The amount of time in seconds which X Plugin waits for
            a TCP/IP port to become free.
          </p></li><li class="listitem"><p><a name="sysvar_mysqlx_socket"></a>
            <a class="link" href="document-store.html#sysvar_mysqlx_socket"><code class="literal">mysqlx_socket</code></a>
</p><a class="indexterm" name="idm139684676044112"></a><a class="indexterm" name="idm139684676043024"></a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_socket"><col width="50%"><col width="50%"><thead><tr><th scope="col">Property</th>
<th scope="col">Value</th>
</tr></thead><tbody><tr><td scope="row"><span class="bold"><strong>Command-Line Format</strong></span></td>
<td><code class="literal">--mysqlx-socket=file_name</code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Introduced</strong></span></td>
<td>5.7.15</td>
</tr><tr><td scope="row"><span class="bold"><strong>System Variable</strong></span></td>
<td><code class="literal"><a class="link" href="document-store.html#sysvar_mysqlx_socket">mysqlx_socket</a></code></td>
</tr><tr><td scope="row"><span class="bold"><strong>Scope</strong></span></td>
<td>Global</td>
</tr><tr><td scope="row"><span class="bold"><strong>Dynamic</strong></span></td>
<td>No</td>
</tr><tr><td scope="row"><span class="bold"><strong>Type</strong></span></td>
<td>string</td>
</tr><tr><td scope="row"><span class="bold"><strong>Default Value</strong></span></td>
<td><code class="literal">/tmp/mysqlx.sock</code></td>
</tr></tbody></table>
</div>
<p>
            The socket where X Plugin listens for connections.
</p></li></ul>
</div>

</div>

</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="x-plugin-system-monitoring"></a>19.7.3 Monitoring X Plugin</h3>

</div>

</div>

</div>
<div class="toc">
<dl class="toc"><dt><span class="section"><a href="document-store.html#x-plugin-monitoring-status-variables">19.7.3.1 Status Variables for X Plugin</a></span></dt></dl>
</div>
<p>
      This section describes how to monitor X Plugin. There are
      two available methods of monitoring, using Performance Schema
      tables or status variables.
</p>
<div class="section">

<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="x-plugin-monitoring-status-variables"></a>19.7.3.1 Status Variables for X Plugin</h4>
</div>
</div>
</div>
<p>
        The status variables have the following meanings.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><a name="statvar_Mysqlx_address"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_address"><code class="literal">Mysqlx_address</code></a>
          </p><p>
            The network address which X Plugin is bound to. If the
            bind has failed, or if the
            <a class="link" href="server-administration.html#sysvar_skip_networking"><code class="literal">skip_networking</code></a> option has
            been used, the value shows <code class="literal">UNDEFINED</code>.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_bytes_sent"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_bytes_sent"><code class="literal">Mysqlx_bytes_sent</code></a>
          </p><p>
            The number of bytes sent through the network.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_bytes_received"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_bytes_received"><code class="literal">Mysqlx_bytes_received</code></a>
          </p><p>
            The number of bytes received through the network.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_execute_sql"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_execute_sql"><code class="literal">Mysqlx_stmt_execute_sql</code></a>
          </p><p>
            The number of StmtExecute requests received for the SQL
            namespace.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_execute_xplugin"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_execute_xplugin"><code class="literal">Mysqlx_stmt_execute_xplugin</code></a>
          </p><p>
            The number of StmtExecute requests received for the
            X Plugin namespace.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_create_collection"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_create_collection"><code class="literal">Mysqlx_stmt_create_collection</code></a>
          </p><p>
            The number of create collection statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_create_collection_index"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_create_collection_index"><code class="literal">Mysqlx_stmt_create_collection_index</code></a>
          </p><p>
            The number of create collection index statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_drop_collection"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_drop_collection"><code class="literal">Mysqlx_stmt_drop_collection</code></a>
          </p><p>
            The number of drop collection statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_drop_collection_index"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_drop_collection_index"><code class="literal">Mysqlx_stmt_drop_collection_index</code></a>
          </p><p>
            The number of drop collection index statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_ensure_collection"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_ensure_collection"><code class="literal">Mysqlx_stmt_ensure_collection</code></a>
          </p><p>
            The number of ensure collection statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_execute_mysqlx"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_execute_mysqlx"><code class="literal">Mysqlx_stmt_execute_mysqlx</code></a>
          </p><p>
            The number of StmtExecute messages received with namespace
            set to <code class="literal">mysqlx</code>.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_list_objects"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_list_objects"><code class="literal">Mysqlx_stmt_list_objects</code></a>
          </p><p>
            The number of list object statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_enable_notices"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_enable_notices"><code class="literal">Mysqlx_stmt_enable_notices</code></a>
          </p><p>
            The number of enable notice statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_disable_notices"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_disable_notices"><code class="literal">Mysqlx_stmt_disable_notices</code></a>
          </p><p>
            The number of disable notice statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_list_notices"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_list_notices"><code class="literal">Mysqlx_stmt_list_notices</code></a>
          </p><p>
            The number of list notice statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_list_clients"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_list_clients"><code class="literal">Mysqlx_stmt_list_clients</code></a>
          </p><p>
            The number of list client statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_kill_client"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_kill_client"><code class="literal">Mysqlx_stmt_kill_client</code></a>
          </p><p>
            The number of kill client statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_stmt_ping"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_stmt_ping"><code class="literal">Mysqlx_stmt_ping</code></a>
          </p><p>
            The number of ping statements received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_insert"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_insert"><code class="literal">Mysqlx_crud_insert</code></a>
          </p><p>
            The number of insert requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_update"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_update"><code class="literal">Mysqlx_crud_update</code></a>
          </p><p>
            The number of update requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_create_view"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_create_view"><code class="literal">Mysqlx_crud_create_view</code></a>
          </p><p>
            The number of create view requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_drop_view"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_drop_view"><code class="literal">Mysqlx_crud_drop_view</code></a>
          </p><p>
            The number of drop view requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_modify_view"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_modify_view"><code class="literal">Mysqlx_crud_modify_view</code></a>
          </p><p>
            The number of modify view requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_delete"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_delete"><code class="literal">Mysqlx_crud_delete</code></a>
          </p><p>
            The number of delete requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_crud_find"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_crud_find"><code class="literal">Mysqlx_crud_find</code></a>
          </p><p>
            The number of find requests received.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_expect_open"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_expect_open"><code class="literal">Mysqlx_expect_open</code></a>
          </p><p>
            The number of expectation blocks opened.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_expect_close"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_expect_close"><code class="literal">Mysqlx_expect_close</code></a>
          </p><p>
            The number of expectation blocks closed.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_rows_sent"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_rows_sent"><code class="literal">Mysqlx_rows_sent</code></a>
          </p><p>
            The number of rows sent back to clients.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_notice_warning_sent"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_notice_warning_sent"><code class="literal">Mysqlx_notice_warning_sent</code></a>
          </p><p>
            The number of warning notices sent back to clients.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_notice_other_sent"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_notice_other_sent"><code class="literal">Mysqlx_notice_other_sent</code></a>
          </p><p>
            The number of other types of notices sent back to clients.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_port"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_port"><code class="literal">Mysqlx_port</code></a>
          </p><p>
            The TCP port which X Plugin is listening to. If a
            network bind has failed, or if the
            <a class="link" href="server-administration.html#option_mysqld_skip-networking"><code class="option">--skip-networking</code></a> option has
            been used, the value shows <code class="literal">UNDEFINED</code>.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_socket"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_socket"><code class="literal">Mysqlx_socket</code></a>
          </p><p>
            The Unix socket which X Plugin is listening to.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_cipher"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_cipher"><code class="literal">Mysqlx_ssl_cipher</code></a>
          </p><p>
            The current SSL cipher (empty for non-SSL connections).
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_cipher_list"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_cipher_list"><code class="literal">Mysqlx_ssl_cipher_list</code></a>
          </p><p>
            A list of possible SSL ciphers (empty for non-SSL
            connections).
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_verify_depth"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_verify_depth"><code class="literal">Mysqlx_ssl_verify_depth</code></a>
          </p><p>
            The certificate verification depth for SSL connections.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_verify_mode"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_verify_mode"><code class="literal">Mysqlx_ssl_verify_mode</code></a>
          </p><p>
            The certificate verification mode for SSL connections.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_version"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_version"><code class="literal">Mysqlx_ssl_version</code></a>
          </p><p>
            The name of the protocol used for SSL connections.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_sessions"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_sessions"><code class="literal">Mysqlx_sessions</code></a>
          </p><p>
            The number of sessions that have been opened.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_sessions_closed"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_sessions_closed"><code class="literal">Mysqlx_sessions_closed</code></a>
          </p><p>
            The number of sessions that have been closed.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_sessions_fatal_error"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_sessions_fatal_error"><code class="literal">Mysqlx_sessions_fatal_error</code></a>
          </p><p>
            The number of sessions that have closed with a fatal error.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_init_error"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_init_error"><code class="literal">Mysqlx_init_error</code></a>
          </p><p>
            The number of errors during initialisation.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_sessions_accepted"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_sessions_accepted"><code class="literal">Mysqlx_sessions_accepted</code></a>
          </p><p>
            The number of session attempts which have been accepted.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_sessions_rejected"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_sessions_rejected"><code class="literal">Mysqlx_sessions_rejected</code></a>
          </p><p>
            The number of session attempts which have been rejected.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_sessions_killed"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_sessions_killed"><code class="literal">Mysqlx_sessions_killed</code></a>
          </p><p>
            The number of sessions which have been killed.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_connections_closed"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_connections_closed"><code class="literal">Mysqlx_connections_closed</code></a>
          </p><p>
            The number of connections which have been closed.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_connections_accepted"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_connections_accepted"><code class="literal">Mysqlx_connections_accepted</code></a>
          </p><p>
            The number of connections which have been accepted.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_connections_rejected"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_connections_rejected"><code class="literal">Mysqlx_connections_rejected</code></a>
          </p><p>
            The number of connections which have been rejected.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_connection_accept_errors"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_connection_accept_errors"><code class="literal">Mysqlx_connection_accept_errors</code></a>
          </p><p>
            The number of connections which have caused accept errors.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_connection_errors"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_connection_errors"><code class="literal">Mysqlx_connection_errors</code></a>
          </p><p>
            The number of connections which have caused errors.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_worker_threads"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_worker_threads"><code class="literal">Mysqlx_worker_threads</code></a>
          </p><p>
            The number of worker threads available.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_worker_threads_active"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_worker_threads_active"><code class="literal">Mysqlx_worker_threads_active</code></a>
          </p><p>
            The number of worker threads currently used.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_active"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_active"><code class="literal">Mysqlx_ssl_active</code></a>
          </p><p>
            If SSL is active.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_ctx_verify_depth"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_ctx_verify_depth"><code class="literal">Mysqlx_ssl_ctx_verify_depth</code></a>
          </p><p>
            

            The certificate verification depth limit currently set in
            ctx.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_ctx_verify_mode"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_ctx_verify_mode"><code class="literal">Mysqlx_ssl_ctx_verify_mode</code></a>
          </p><p>
            The certificate verification mode currently set in ctx.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_finished_accepts"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_finished_accepts"><code class="literal">Mysqlx_ssl_finished_accepts</code></a>
          </p><p>
            The number of successful SSL connections to the server.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_accepts"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_accepts"><code class="literal">Mysqlx_ssl_accepts</code></a>
          </p><p>
            The number of accepted SSL connections.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_server_not_after"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_server_not_after"><code class="literal">Mysqlx_ssl_server_not_after</code></a>
          </p><p>
            The last date for which the SSL certificate is valid.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_server_not_before"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_server_not_before"><code class="literal">Mysqlx_ssl_server_not_before</code></a>
          </p><p>
            The first date for which the SSL certificate is valid.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_ssl_accept_renegotiates"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_ssl_accept_renegotiates"><code class="literal">Mysqlx_ssl_accept_renegotiates</code></a>
          </p><p>
            The number of negotiations needed to establish the
            connection.
          </p></li><li class="listitem"><p><a name="statvar_Mysqlx_errors_sent"></a>
            <a class="link" href="document-store.html#statvar_Mysqlx_errors_sent"><code class="literal">Mysqlx_errors_sent</code></a>
          </p><p>
            The number of errors sent to clients.
</p></li></ul>
</div>

</div>

</div>

</div>

</div>
<div class="copyright-footer">

</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="mysql-shell-userguide.html">Prev</a></td>
<td width="20%" align="center"><a accesskey="u" href="">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="mysql-innodb-cluster-userguide.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 18 MySQL Shell</td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top">Chapter 20 InnoDB Cluster</td>
</tr>
</table>
</div>
</body>
</html>
